PDA

View Full Version : Error handling guidelines?



bitflyer
2nd June 2010, 14:54
Are there any general guidelines about how to implement error handling in Qt code? What I mean are things like checking input parameters to functions and what to do in case of invalid parameters:

fail silently and do nothing?
return an error code as the result?
return 'false' and log an error message somewhere for the caller to get it?
emit a warning message and use a default value instead?
emit a warning and abort (Q_ASSERT, qFail(), ...)?
raise an exception?
or...?

Well I guess it depends also on the application what would be the correct action. Anyway, I haven't seen these issues discussed much in the Qt documentation, so I wanted to know if there are some common practices people usually follow?

high_flyer
2nd June 2010, 16:09
I haven't seen these issues discussed much in the Qt documentation,
Thats because its not Qt issue.
This is not even a language issue.

There are no general guide lines for that.
There are various philosophies for error handling, and you should pick the one that best suits your project.
http://en.wikibooks.org/wiki/C_Programming/Error_handling
http://en.wikipedia.org/wiki/Exception_handling