On Tue, 26 Jul 2005 11:57:14 +0200, Dietmar Kuehl
<di***********@yahoo.com> wrote:
* Steven T. Hatton: Does anyone have an opinion as to which of the std::exception derivatives
is most suited from deriving file I/O exceptions from?
'std::ios_base::failure' could also be a reasonable candidate.
I disagree. Presently, class failure is thrown by the library to
indicate some combination of state bits have been set. Code that
catches exceptions of this type will be expecting the exception to
indicate this condition, and almost certainly will be broken by this
change.
Furthermore, there is no particularly compelling reason to derive from
this class, as its common meaning is not applicable to a general I/O
error, and thus deriving from this class adds no additional meaning
over simply deriving from std::exception.
The general guideline is to use one of the specific <stdexcept>
exceptions if they fit, otherwise use std::runtime_error for runtime
exceptional conditions (non-bugs), and std::logic_error for bug
conditions.
Arguably, for the latter class of "logic errors," it is better to
simply use assert() or similar, instead of (or in addition to,
depending) throwing an exception.
Aaron W. LaFramboise