I've watched these threads before and found that they go
around and around. The reason is because you all are jumping
the gun seeking the "one and only" thing instead of being
patient and doing some research. Error handling is
application-specific.
Even within a single application, different types of errors will
require different types of handling. For that matter, the same
type of error may require different handling in different
contexts: a write error in a log file should probably be
ignored; a write error in the program output (e.g. when writing
the object file in a compiler) should probably result in the
program terminating with an error status (after clean-up---I
can't think of any case where a write error should result in an
abort).
Without a well-defined problem, discussions get no where
toward solution and no one learns anything. James, you said,
"aborting is not necessarily bad". Well, of course not. It
depends on the application.
Which is what I said. Most of the time, aborting is the
appropriate reaction, and it is the obvious choice for a default
action, but I'm well aware that there are exceptions: game
programs, for example, and possibly light weight GUI client
code.
It is but one of many avenues to take upon detecting
(detection is a key concept) that a potentially "disastrous"
thing will occur unless processing doesn't take a side road
immediately. If you believe what I just said, and I believe
you do, then you see why I question those who consider C++
exceptions as an error management strategy. C++ exceptions are
JUST a mechanism. NOT a solution to the error management
problem.
I don't think anyone has reasonably argued that exceptions are
an "error managment strategy". First, as you say, they are a
just a mechanism---a tool to implement a strategy, and not a
strategy. And second, they only address one aspect of error
management: reporting. Error management involves three aspects:
detection, reporting and handling. Exceptions don't help in
detection, nor in handling. They just simplify reporting when
the error must be handled far up the call stack. (Which means
that they are of no use when the error must be handled
immediately.)
Yet I am sure that chatter and banter about the
mechanisms rather than the problem will continue. How to
accellerate the learning is the question.
Maybe. (Read, I'm not sure 'bout that). I don't know what you
mean. Did you just elevate "function argument requirements" to
"exception specification"?
I didn't elevate anything. I'm just describing what exception
specifications do.
If so, given the current "climate" and confusion with error
handling, you'd expect me to BELIEVE your "exception
specification" as some kind of authoritative thing?
It is. Since the standard says it is. A function with an
exception specification "throw (std::bad_alloc)" may not exit by
any exception other than std::bad_alloc or an exception which
derives from std::bad_alloc. And the standard is authoritive.
Whether such a "contract" is practically useful is another
issue. In practice, the only contract expressible by exception
specifications which I've found useful is "throw()". In
otherwords, that the function will not exit by an exception,
period. Without it, you can't really write exception safe code.
C'mon, let's get real. "Before", there was "a function has, "a
contract". Are you suggesting now that a function has "an
exception specification" all is good? C'mon, who uses those
things in C++? That is so yesterday. It failed. Didn't it?
I'm having difficulty parsing what you're trying to say. But
programming by contract certainly hasn't failed, and is still
considered a good thing in most circles. As for exception
specifications, they're just another part of the contract. So
one can't say that they've failed. What one can say is that the
contract they express is not all that useful (with the exception
of an empty exception specification---a no-throw guarantee).
No doubt you seek to write meaningless definitions for specifications? ;P
<-(combinatorial emoticon) (Should I patent it?).
I didn't write the definition of exception specifications. It's
in the standard.
Define "unexpected exception" please. I didn't know that C++
recognized such a beast. I can't quote anything from the
standard or the tomes, but in my mind remains that exceptions
in C++ are EXPECTED things. Am I wrong or are you? One of us
has to be.
I didn't write that, so I can't be sure, but a priori, an
"unexpected exception" is one that the programmer didn't expect;
that he wasn't prepared to handle.
To be real, detection is all about preventing "undefined
behaviour". "error" is not pondered about enough. Then again,
I've never been taught programming other than Jr. College
where it was Pascal I think and everyone had to do it (that's
not important), so I don't know who failed the test in the
course and who didn't because I don't know what they/you are
teaching.
Did you just say, "C++ exceptions used as a crutch to
understanding the problem"?
No. I never said that. I've always argued that exceptions are
a tool, to be used when appropriate, but that they don't solve
all problems. (Many years ago, I was rather down on exceptions,
because everyone was constantly saying that as soon as compilers
supported them, all problems concerning errors would disappear,
and no one was addressing the real problems concerning
additional paths in the program flow that they raise. Since
then, our understanding of the issues has evolved.)