Merge pull request #129 from ianrrees/20160327-use-SystemExitException-code

More fixes around Python exit codes
This commit is contained in:
wwmayer 2016-03-28 10:17:13 +02:00
commit c69aae4b2f
5 changed files with 23 additions and 20 deletions

View File

@ -131,7 +131,7 @@ SystemExitException::SystemExitException()
} }
SystemExitException::SystemExitException(const SystemExitException &inst) SystemExitException::SystemExitException(const SystemExitException &inst)
: Exception(inst) : Exception(inst), _exitCode(inst._exitCode)
{ {
} }

View File

@ -1553,8 +1553,7 @@ void Application::runApplication(void)
Base::Console().Log("Init: Creating Gui::Application and QApplication\n"); Base::Console().Log("Init: Creating Gui::Application and QApplication\n");
// if application not yet created by the splasher // if application not yet created by the splasher
int argc = App::Application::GetARGC(); int argc = App::Application::GetARGC();
int systemExit = 1000; GUISingleApplication mainApp(argc, App::Application::GetARGV());
GUISingleApplication mainApp(argc, App::Application::GetARGV(), systemExit);
// check if a single or multiple instances can run // check if a single or multiple instances can run
it = cfg.find("SingleInstance"); it = cfg.find("SingleInstance");
@ -1786,9 +1785,11 @@ void Application::runApplication(void)
boost::interprocess::file_lock flock(s.str().c_str()); boost::interprocess::file_lock flock(s.str().c_str());
flock.lock(); flock.lock();
int ret = mainApp.exec(); mainApp.exec();
if (ret == systemExit) // Qt can't handle exceptions thrown from event handlers, so we need
throw Base::SystemExitException(); // to manually rethrow SystemExitExceptions.
if(mainApp.caughtException.get())
throw Base::SystemExitException(*mainApp.caughtException.get());
// close the lock file, in case of a crash we can see the existing lock file // close the lock file, in case of a crash we can see the existing lock file
// on the next restart and try to repair the documents, if needed. // on the next restart and try to repair the documents, if needed.

View File

@ -54,14 +54,13 @@
#include <Base/Console.h> #include <Base/Console.h>
#include <Base/Exception.h> #include <Base/Exception.h>
#include <Base/Interpreter.h>
#include <App/Application.h> #include <App/Application.h>
using namespace Gui; using namespace Gui;
GUIApplication::GUIApplication(int & argc, char ** argv, int exitcode) GUIApplication::GUIApplication(int & argc, char ** argv)
: GUIApplicationNativeEventAware(argc, argv), systemExit(exitcode) : GUIApplicationNativeEventAware(argc, argv)
{ {
} }
@ -82,8 +81,9 @@ bool GUIApplication::notify (QObject * receiver, QEvent * event)
else else
return QApplication::notify(receiver, event); return QApplication::notify(receiver, event);
} }
catch (const Base::SystemExitException&) { catch (const Base::SystemExitException &e) {
qApp->exit(systemExit); caughtException.reset(new Base::SystemExitException(e));
qApp->exit(e.getExitCode());
return true; return true;
} }
catch (const Base::Exception& e) { catch (const Base::Exception& e) {
@ -225,8 +225,8 @@ public:
bool running; bool running;
}; };
GUISingleApplication::GUISingleApplication(int & argc, char ** argv, int exitcode) GUISingleApplication::GUISingleApplication(int & argc, char ** argv)
: GUIApplication(argc, argv, exitcode), : GUIApplication(argc, argv),
d_ptr(new Private(this)) d_ptr(new Private(this))
{ {
d_ptr->setupConnection(); d_ptr->setupConnection();

View File

@ -25,7 +25,9 @@
#define GUI_APPLICATION_H #define GUI_APPLICATION_H
#include "GuiApplicationNativeEventAware.h" #include "GuiApplicationNativeEventAware.h"
#include <Base/Interpreter.h> // For Base::SystemExitException
#include <QList> #include <QList>
#include <boost/shared_ptr.hpp>
class QSessionManager; class QSessionManager;
@ -39,7 +41,7 @@ class GUIApplication : public GUIApplicationNativeEventAware
Q_OBJECT Q_OBJECT
public: public:
explicit GUIApplication(int & argc, char ** argv, int exitcode); explicit GUIApplication(int & argc, char ** argv);
virtual ~GUIApplication(); virtual ~GUIApplication();
/** /**
@ -49,11 +51,11 @@ public:
bool notify (QObject * receiver, QEvent * event); bool notify (QObject * receiver, QEvent * event);
void commitData(QSessionManager &manager); void commitData(QSessionManager &manager);
/// Pointer to exceptions caught in Qt event handler
boost::shared_ptr<Base::SystemExitException> caughtException;
protected: protected:
bool event(QEvent * event); bool event(QEvent * event);
private:
int systemExit;
}; };
class GUISingleApplication : public GUIApplication class GUISingleApplication : public GUIApplication
@ -61,7 +63,7 @@ class GUISingleApplication : public GUIApplication
Q_OBJECT Q_OBJECT
public: public:
explicit GUISingleApplication(int & argc, char ** argv, int exitcode); explicit GUISingleApplication(int & argc, char ** argv);
virtual ~GUISingleApplication(); virtual ~GUISingleApplication();
bool isRunning() const; bool isRunning() const;

View File

@ -125,8 +125,8 @@ int main( int argc, char ** argv )
try { try {
Application::runApplication(); Application::runApplication();
} }
catch (const Base::SystemExitException&) { catch (const Base::SystemExitException &e) {
exit(0); exit(e.getExitCode());
} }
catch (const Base::Exception& e) { catch (const Base::Exception& e) {
e.ReportException(); e.ReportException();