Merge pull request #129 from ianrrees/20160327-use-SystemExitException-code
More fixes around Python exit codes
This commit is contained in:
commit
c69aae4b2f
|
@ -131,7 +131,7 @@ SystemExitException::SystemExitException()
|
|||
}
|
||||
|
||||
SystemExitException::SystemExitException(const SystemExitException &inst)
|
||||
: Exception(inst)
|
||||
: Exception(inst), _exitCode(inst._exitCode)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1553,8 +1553,7 @@ void Application::runApplication(void)
|
|||
Base::Console().Log("Init: Creating Gui::Application and QApplication\n");
|
||||
// if application not yet created by the splasher
|
||||
int argc = App::Application::GetARGC();
|
||||
int systemExit = 1000;
|
||||
GUISingleApplication mainApp(argc, App::Application::GetARGV(), systemExit);
|
||||
GUISingleApplication mainApp(argc, App::Application::GetARGV());
|
||||
|
||||
// check if a single or multiple instances can run
|
||||
it = cfg.find("SingleInstance");
|
||||
|
@ -1786,9 +1785,11 @@ void Application::runApplication(void)
|
|||
boost::interprocess::file_lock flock(s.str().c_str());
|
||||
flock.lock();
|
||||
|
||||
int ret = mainApp.exec();
|
||||
if (ret == systemExit)
|
||||
throw Base::SystemExitException();
|
||||
mainApp.exec();
|
||||
// Qt can't handle exceptions thrown from event handlers, so we need
|
||||
// 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
|
||||
// on the next restart and try to repair the documents, if needed.
|
||||
|
|
|
@ -54,14 +54,13 @@
|
|||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Interpreter.h>
|
||||
|
||||
#include <App/Application.h>
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
GUIApplication::GUIApplication(int & argc, char ** argv, int exitcode)
|
||||
: GUIApplicationNativeEventAware(argc, argv), systemExit(exitcode)
|
||||
GUIApplication::GUIApplication(int & argc, char ** argv)
|
||||
: GUIApplicationNativeEventAware(argc, argv)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -82,8 +81,9 @@ bool GUIApplication::notify (QObject * receiver, QEvent * event)
|
|||
else
|
||||
return QApplication::notify(receiver, event);
|
||||
}
|
||||
catch (const Base::SystemExitException&) {
|
||||
qApp->exit(systemExit);
|
||||
catch (const Base::SystemExitException &e) {
|
||||
caughtException.reset(new Base::SystemExitException(e));
|
||||
qApp->exit(e.getExitCode());
|
||||
return true;
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
|
@ -225,8 +225,8 @@ public:
|
|||
bool running;
|
||||
};
|
||||
|
||||
GUISingleApplication::GUISingleApplication(int & argc, char ** argv, int exitcode)
|
||||
: GUIApplication(argc, argv, exitcode),
|
||||
GUISingleApplication::GUISingleApplication(int & argc, char ** argv)
|
||||
: GUIApplication(argc, argv),
|
||||
d_ptr(new Private(this))
|
||||
{
|
||||
d_ptr->setupConnection();
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
#define GUI_APPLICATION_H
|
||||
|
||||
#include "GuiApplicationNativeEventAware.h"
|
||||
#include <Base/Interpreter.h> // For Base::SystemExitException
|
||||
#include <QList>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
class QSessionManager;
|
||||
|
||||
|
@ -39,7 +41,7 @@ class GUIApplication : public GUIApplicationNativeEventAware
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GUIApplication(int & argc, char ** argv, int exitcode);
|
||||
explicit GUIApplication(int & argc, char ** argv);
|
||||
virtual ~GUIApplication();
|
||||
|
||||
/**
|
||||
|
@ -49,11 +51,11 @@ public:
|
|||
bool notify (QObject * receiver, QEvent * event);
|
||||
void commitData(QSessionManager &manager);
|
||||
|
||||
/// Pointer to exceptions caught in Qt event handler
|
||||
boost::shared_ptr<Base::SystemExitException> caughtException;
|
||||
|
||||
protected:
|
||||
bool event(QEvent * event);
|
||||
|
||||
private:
|
||||
int systemExit;
|
||||
};
|
||||
|
||||
class GUISingleApplication : public GUIApplication
|
||||
|
@ -61,7 +63,7 @@ class GUISingleApplication : public GUIApplication
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GUISingleApplication(int & argc, char ** argv, int exitcode);
|
||||
explicit GUISingleApplication(int & argc, char ** argv);
|
||||
virtual ~GUISingleApplication();
|
||||
|
||||
bool isRunning() const;
|
||||
|
|
|
@ -125,8 +125,8 @@ int main( int argc, char ** argv )
|
|||
try {
|
||||
Application::runApplication();
|
||||
}
|
||||
catch (const Base::SystemExitException&) {
|
||||
exit(0);
|
||||
catch (const Base::SystemExitException &e) {
|
||||
exit(e.getExitCode());
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
e.ReportException();
|
||||
|
|
Loading…
Reference in New Issue
Block a user