[SOLVED] Looking for examples on handling errors and validations in Qt?
-
I get that people working in Qt prefer error codes. But then how do I manage the error codes? Having habituated to using exception for well, exception handling, I can't wrap my head around using error codes.
I wish there were a good, neat example that demonstrates errror/exception handling in Qt. I would appreciate links to such examples.
-
Hi,
Generally when handling error codes there are two possibilities:
Stop the flow of execution if there are any errors
React on specific error(s)
For number one, an if condition is what is used
For number two, you can use a switch statement or an if, else if blockAlso depending on your work flow, you might propagate the error further
Hope it helps
-
Ok. That is useful.
And how do I manage all the error codes? What I have thought of is to use enum for each class, that would contain error codes throwable by that class.
However, I am still confused as to where to put human-readable error messages. I feel that the same class is not the place, as it could be desirable to display different error messages for the same error code.
My current approach is to have ApplicationController class implement a method that maps the error codes to readable messages.Any ideas on that?
[quote author="SGaist" date="1376256485"]Hi,
Generally when handling error codes there are two possibilities:
Stop the flow of execution if there are any errors
React on specific error(s)
For number one, an if condition is what is used
For number two, you can use a switch statement or an if, else if blockAlso depending on your work flow, you might propagate the error further
Hope it helps[/quote]
-
You can have an error class that you can return and query for additional informations, like QSqlError or QDBusError
-
You're welcome !
One other thing, if one of your error class is used to show a string version of your errors in a GUI, you might want to translate them
-
-
Why are your thinking about the resources system ?