C++ (Qt)#include <QtGui/QApplication>#include "mainwindow.h" int main(int argc, char *argv[]){ try { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } catch ( ... ) { qDebug( "Eception" ); }}
C++ (Qt)void MainWindow::on_b1_clicked(){ int i=0; setWindowTitle(QString::number(1/i));} void MainWindow::on_b2_clicked(){ throw new std::exception();}
C++ (Qt)int main(int argc, char *argv[]){ QApplication a(argc, argv); try { MainWindow w; w.show(); } catch ( ... ) { qDebug( "Exception" ); } return a.exec();}
C++ (Qt)#include <QtGui/QApplication>#include <QtGui/QWidget> class Widget : public QWidget{ Q_OBJECT public: Widget(QWidget *parent = 0) { throw std::exception(); }}; int main(int argc, char *argv[]){ QApplication a(argc, argv); try { Widget w; w.show(); } catch (...) { qDebug("exception"); } return a.exec();}
C++ (Qt)#include <QtGui/QApplication>#include <QtGui/QWidget>#include <QtGui/QPushButton> class Widget : public QWidget{ Q_OBJECT public: Widget(QWidget *parent = 0) { QPushButton *b = new QPushButton("exception", this); connect(b, SIGNAL(clicked()), SLOT(throwException())); } private slots: void throwException() { throw std::exception(); }}; int main(int argc, char *argv[]){ QApplication a(argc, argv); Widget w; try { w.show(); } catch (...) { qDebug("exception"); } return a.exec();}
class App : public QApplication{ Q_OBJECT typedef QApplication Base;...Q_SIGNALS: void onException(const std::exception& exception, bool& handled);protected: virtual bool notify(QObject* receiver, QEvent* event) { try { return Base::notify(receiver, event); } catch (const std::exception& exception) { bool handled = false; Q_EMIT onException(exception, handled); if (!handled) QMessageBox::critical(0, QApplication::instance()->applicationName(), exception.what(), QMessageBox::Ok, QMessageBox::NoButton); } catch (...) { QMessageBox::critical(0, QApplication::instance()->applicationName(), "Application general failure", QMessageBox::Ok, QMessageBox::NoButton); } return false; }};