[Qt-interest] How to handle exceptions in Qt
Santhosh Y
santhosh at softjin.com
Wed Dec 16 16:20:18 CET 2009
Hi,
In following snippet, I purposefully made a widget to NULL, and calling
a function on that.
It is crashing the moment it access a fn on that NULL pointer.
But my expectation was that, control will reach catch(...) and then
printing std::cout statement.
But I am not seeing this message on my console.
To catch the exceptions, I also overridden QApplication::notify(). It is
also not helping!
What is the issue here ?
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
/// QApplication derived class
class MyApp : public QApplication
{
Q_OBJECT
public:
MyApp(int& argc, char **argv) : QApplication(argc,argv) {}
bool notify( QObject * receiver, QEvent * event )
{
try {
// call to the ancestor's method
return QApplication::notify(receiver,event);
}
catch( ... ) {
std::cout << "Unknown exception. Exit." << std::endl;
exit(1);
}
}
};
/// QMainWindow derived class
class Launcherview : public QMainWindow {};
/// Function throwing the EXCEPTION
void
LauncherView::createTopDockWidgetArea ()
{
try {
// Creation of DockWidget
QDockWidget* mainWndwTaskBar = new QDockWidget();
// purposefully made it to NULL; to check whether exception is
caught ?
mainWndwTaskBar = NULL;
// setting no dock features
mainWndwTaskBar->setFeatures (QDockWidget::NoDockWidgetFeatures);
} catch (...) {
std::cout << "Exception Caught ..... " << std::endl;
throw;
}
}
/// It was crashing in the following API of Qt infrastructure which is
CORRECT.
/// Qt DockWidget class
void QDockWidget::setFeatures(QDockWidget::DockWidgetFeatures features)
{
Q_D(QDockWidget);
}
--
----------------------------------------------------
Y Santhosh Kumar -
Senior Software Engineer,
SoftJin Technologies Pvt Ltd,
www.softjin.com
----------------------------------------------------
Business Disclaimer
____________________________________________________________
This e-mail message and any files transmitted with it are intended solely
for the use of the individual or entity to which they are addressed. It
may contain confidential, proprietary or legally privileged information.
If you are not the intended recipient please be advised that you have
received this message in error and any use is strictly prohibited. Please
immediately delete it and all copies of it from your system, destroy any
hard copies of it and notify the sender by return mail. You must not,
directly or indirectly, use, disclose, distribute, print, or copy any part of
this message if you are not the intended recipient.
___________________________________________________________
More information about the Qt-interest-old
mailing list