An exceptional misunderstanding.
IMHO The exceptions is for exceptional errors. Not for every error that can occur in a programs lifetime. The error codes don't require the programmers to check every error. Exceptions are for errors that occur when it is not safe to continue. Not for general error handling.
Janne V
Tuesday, October 14, 2003
IMHO You should never, ever have exception error handling and non-exception error handling intermixing.
It is fiendishly difficult to debug those interactions.
Gustavo W.
Tuesday, October 14, 2003
That's not entirely true. The Symbian OS has both exceptions and return codes. Exceptions are used almost entirely for very exceptional conditions (out-of-bound array access, memory allocation failure, etc). Conversely, error codes are used for all file access methods and the like.
It seems the general rule is that exceptions are triggered mostly by program bugs (like the out-of-bound array access) or very unusual outside circumstances (allocation failure). Error codes are used for more typical errors (file does not exist, file locked, etc). Symbian also provides utility functions to turn error codes into exceptions.
I've found this seamless enough in their API that I don't really notice it all that much. It probably also helps that Symbian has very strict naming convensions: All methods that can raise an exception are marked with a trailing L (for leave; a "leave" is a Symbian exception).
Almost Anonymous
Tuesday, October 14, 2003
here here to symbian!
i like i
Wednesday, October 15, 2003
The "trailing L" Symbian convention also negates the main objection Joel has to exceptions: that it's unclear which functions throw them.
The downside of leaves is that they don't really include enough information in some cases (an integer error code isn't enough). Also, there are relatively few standard error codes defined, leading to the dreaded "Not Found" code being used for almost everything.
I agree, however, that it can be incredibly difficult to debug a function which can either return an error or throw an exception, unless the documentation is very clear.
Ashley
Wednesday, October 15, 2003
Recent Topics
Fog Creek Home
|