Where should i use an except block in order to log exceptions of a QApplication
?
This doesn't seem to work:
app = QtGui.QApplication(sys.argv)
MainWindow = MainWindow()
MainWindow.show()
try:
eventLoop = app.exec_()
except Exception, e:
log.exception(str(e))
as the exception won't even reach that block.
So, what should QApplication::notify () return when it catches an exception? Sends event to receiver: receiver->event (event). Returns the value that is returned from the receiver's event handler.
Essentially what you need to do is add an uncaught exception handler in your Application class that will log the errors before the app has to terminate. First, create this exception handler: And finally, register this crash handler in your application class:
The .NET Framework provides a couple of events that you can use to catch unhandled exceptions. You only need to register for these events once in your code when your application starts up. For ASP.NET, you would do this in the Startup class or Global.asax. For Windows applications, it could be the first couple lines of code in the Main () method.
Uncaught Exceptions in Java PreviousNext In java, assume that, if we do not handle the exceptions in a program. In this case, when an exception occurs in a particular function, then Java prints a exception message with the help of uncaught exception handler.
Throwing exceptions from an event handler is not supported in Qt. You must reimplement QApplication::notify() and catch all exceptions there.
Overwrite the function bool QApplication::notify(QObject * receiver, QEvent *event) so that it catches all thrown exceptions.
You can implement like this.
virtual bool notify(QObject * receiver, QEvent * event)
{
try
{
return QApplication::notify(receiver, event);
}
catch(std::exception& e)
{
qDebug() << "Exception thrown:" << e.what();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With