Re: Standard C++ file size ???
On Jul 7, 5:36 pm, Peter Olcott <NoS...@OCR4Screen.com> wrote:
On 7/7/2010 11:10 AM, James Kanze wrote:
[...]
At least until the code is fully operational throwing non-text
exceptions makes the code substantially more complex than
necessary.
Just the opposite. Throwing exceptions of class type makes the
code substantially simpler than using a non-class type.
Making code substantially more complex than necessary
drastically increases development time, and reduces
reliability.
Which is why you shouldn't throw exceptions of text type.
Macros can be added to provide the file name and line number of the
error. I forgot what these are, do you remember? This can even further
simplify error detection and correction.
__FILE__ and __LINE__.
The class type you throw generally does have a text element, so
you can insert these if necessary. Typically, however, I'd say
that if they're useful, the error is one that should be handled
as an assertion failure, and not an exception. (And even in
assertion failure, their utility is questionable. How does it
help to know that your code failed in vector_impl.h, line 1234?
You really need a stack walkback.)
In what cases would the finer granularity of exception
processing be useful?
Almost all.
I can not think of any recoverable exceptions besides "file
does not exist, try another filename". Many exceptions either
indicate a fatal I/O error or a bug in the program, and these
merely need to be reported.
If all that is needed is to report and abort, you don't need an
exception. It's not always necessary to distinguish between
exceptions, but when testing, it can be very useful, and there
are also cases where it is useful in application code as well.
(If you're invoking a recursive descent parser, for example, you
definitely want to be able to distinguish between a parse error
and other errors.)
--
James Kanze