PDA

View Full Version : Standard Way to Handle Errors/Exceptions



wswartzendruber
30th September 2009, 03:02
In .NET we have exceptions, but Qt4 seems to do without them.

What's the religion for error handling?

wysota
30th September 2009, 09:20
In .NET we have exceptions, but Qt4 seems to do without them.
In C++ we have exceptions as well.


What's the religion for error handling?

There is no religion. You can use exceptions if you want. Or you can have a member variable determining the current error state of the object like Qt often does (i.e. QSqlError).

scascio
30th September 2009, 10:07
I noticed that exceptions thrown in a slot cannot be caught in the code where the signal is emitted, according to signal/slot handling.
So, for error management in a slot, treat your errors there and do not throw exception.

Is that the case you are talking about?

wysota
30th September 2009, 10:49
I noticed that exceptions thrown in a slot cannot be caught in the code where the signal is emitted, according to signal/slot handling.
I'd say it depends on the type of signal-slot connection (with queued connections there is no chance of catching the exception). But there is a question why would the emitting object catch that exception if it's not related in any way to the object throwing the exception. Also remember there may be more than one slot connected to the same signal and the execution should not depend on the order of slots being called. I'd say that's why you shouldn't use exceptions with signal-slot connections.