Qt and error handling strategy


Question

Actually, I do understand major pros and cons of using exceptions. And I use them in my projects by default as error-handling strategy. But now I'm starting a Windows CE project with Qt library, and I see that Qt creators refused to use exceptions in the class hierarchy.

So, if I use exceptions I will need to carefully translate them to and from error codes (or some objects, or just swallow) on my/Qt code bounds. Otherwise, I can refuse to use exceptions in my code and switch to some other strategy.

What would be the best error handling strategy in my case - to use exceptions or to use error-codes, or etc...? Do you have experience with Qt development and what error handling strategy did you use?

1
12
10/19/2009 2:17:42 PM

Override QApplication::notify() and handle exceptions there (not 100% on the return value). You can "throw" exceptions from signal handlers but they don't get propagated to Qt in this way.

bool
notify(QObject * rec, QEvent * ev)
{
  try
  {
    return QApplication::notify(rec,ev);
  }
  catch(my::Exception & e)
  {
    QMessageBox::warning(0,
                         tr("An error occurred"),
                         e.message());
  }
  catch(...)
  {
    QMessageBox::warning(0,
                         tr("An unexpected error occurred"),
                         tr("This is likely a bug."));
  }
  return false;
8
10/16/2009 2:35:54 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon