Proper handling of SystemExitException in Python

This commit is contained in:
wmayer 2012-08-11 10:58:54 +02:00
parent 408e1dc8e1
commit 0d351e98e2
8 changed files with 37 additions and 18 deletions

View File

@ -1457,9 +1457,10 @@ namespace Gui {
*/
class GUIApplication : public GUIApplicationNativeEventAware
{
int systemExit;
public:
GUIApplication(int & argc, char ** argv)
: GUIApplicationNativeEventAware(argc, argv)
GUIApplication(int & argc, char ** argv, int exitcode)
: GUIApplicationNativeEventAware(argc, argv), systemExit(exitcode)
{
}
@ -1480,6 +1481,10 @@ public:
else
return QApplication::notify(receiver, event);
}
catch (const Base::SystemExitException&) {
qApp->exit(systemExit);
return true;
}
catch (const Base::Exception& e) {
Base::Console().Error("Unhandled Base::Exception caught in GUIApplication::notify.\n"
"The error message is: %s\n", e.what());
@ -1543,7 +1548,8 @@ 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();
GUIApplication mainApp(argc, App::Application::GetARGV());
int systemExit = 1000;
GUIApplication mainApp(argc, App::Application::GetARGV(), systemExit);
// set application icon and window title
const std::map<std::string,std::string>& cfg = App::Application::Config();
std::map<std::string,std::string>::const_iterator it;
@ -1716,9 +1722,15 @@ void Application::runApplication(void)
Base::Console().Log("Init: Entering event loop\n");
try {
mainApp.exec();
int ret = mainApp.exec();
if (ret == systemExit)
throw Base::SystemExitException();
}
catch(...) {
catch (const Base::SystemExitException&) {
Base::Console().Message("System exit\n");
throw;
}
catch (...) {
// catching nasty stuff coming out of the event loop
App::Application::destructObserver();
Base::Console().Error("Event loop left through unhandled exception\n");

View File

@ -281,6 +281,9 @@ void Command::invoke(int i)
if (isActive())
activated( i );
}
catch (const Base::SystemExitException&) {
throw;
}
catch (Base::PyException &e) {
e.ReportException();
Base::Console().Error("Stack Trace: %s\n",e.getStackTrace().c_str());

View File

@ -233,7 +233,7 @@ void MacroManager::run(MacroType eType,const char *sName)
Base::Interpreter().runFile(sName, this->localEnv);
}
catch (const Base::SystemExitException&) {
qApp->quit();
throw;
}
catch (const Base::PyException& e) {
Base::Console().Error("%s%s: %s\n",

View File

@ -1157,8 +1157,7 @@ void MainWindow::delayedStartup()
App::Application::processCmdLineFiles();
}
catch (const Base::SystemExitException&) {
QApplication::quit();
return;
throw;
}
const std::map<std::string,std::string>& cfg = App::Application::Config();

View File

@ -709,7 +709,7 @@ void PythonConsole::runSource(const QString& line)
}
if (ret == QMessageBox::Yes) {
PyErr_Clear();
qApp->quit();
throw;
}
else {
PyErr_Clear();

View File

@ -300,6 +300,9 @@ int main( int argc, char ** argv )
else
App::Application::runApplication();
}
catch (const Base::SystemExitException&) {
exit(0);
}
catch (const Base::Exception& e) {
Base::Console().Error("%s\n", e.what());
}

View File

@ -114,7 +114,7 @@ BrowserView::BrowserView(QWidget* parent)
connect(view, SIGNAL(loadProgress(int)),
this, SLOT(onLoadProgress(int)));
connect(view, SIGNAL(loadFinished(bool)),
this, SLOT(onLoadFinished()));
this, SLOT(onLoadFinished(bool)));
connect(view, SIGNAL(linkClicked(const QUrl &)),
this, SLOT(onLinkClicked(const QUrl &)));
connect(view->page(), SIGNAL(downloadRequested(const QNetworkRequest &)),
@ -242,12 +242,14 @@ void BrowserView::onLoadProgress(int step)
bar->setValue(step);
}
void BrowserView::onLoadFinished()
void BrowserView::onLoadFinished(bool ok)
{
QProgressBar* bar = Sequencer::instance()->getProgressBar();
bar->setValue(100);
bar->hide();
getMainWindow()->statusBar()->showMessage(QString());
if (ok) {
QProgressBar* bar = Sequencer::instance()->getProgressBar();
bar->setValue(100);
bar->hide();
getMainWindow()->statusBar()->showMessage(QString());
}
isLoading = false;
}

View File

@ -92,10 +92,10 @@ public:
protected Q_SLOTS:
void onLoadStarted();
void onLoadProgress(int);
void onLoadFinished();
void onLinkClicked ( const QUrl & url ) ;
void onLoadFinished(bool);
void onLinkClicked (const QUrl& url);
bool chckHostAllowed(const QString& host);
void onDownloadRequested(const QNetworkRequest & request);
void onDownloadRequested(const QNetworkRequest& request);
private:
WebView* view;