Re: Assertion vs Exception Handling
"Leigh Johnston" <leigh@i42.co.uk> wrote:
"Daniel T." <daniel_t@earthlink.net> wrote:
Exceptions are for errors, that's what they were designed for. If
your program can handle some particular condition and continue
normal execution, how is that condition an error? The answer is, it
isn't. Invalid user input is a good example of something that should
*not* cause an error in your program, your program should be able to
deal with such input gracefully.
My point is that you can use exceptions to gracefully handle bad
input. Having an if statement with error code return for every control
in your dialog is not graceful.
In my experience, having a slew of catch blocks each dealing with a
different type of user input is even less graceful.
Exceptions can be used for both fatal errors and non-fatal valid
runtime errors - two types of errors.
The fundamental difference between us, I think, is how we define
"error." I define it as something the program cannot recover from. When
the design says, "If the user does X, then the program must to Y," I
don't call it an error when the user does X. If the design requires that
condition A must pertain at point B, and condition A does not pertain at
point B; I call *that* an error.