Edward Chen wrote:Unchecked exception is a bug, "cannot be reasonably recovered from at run time". I don't understand this statement.
I would disagree with the wording that the author of that statement used. An error is something that cannot be reasonably recovered from. An unchecked exception is simply an exception that you are not required to explicitly catch or throw up the stack. While they may be things that shouldn't normally occur in a well designed program, I think the real reason for having them unchecked is simply that it would be incredibly tedious and clutter up the code--you don't want to have to put every division operation in a try-catch block because of the possibility of zero divisor. On the other hand, that doesn't mean that you might not choose to use them in certain circumstances. There might be situations where you prefer to put an arithmetic calculation in a try-catch block rather than adding code to check if any divisors are zero. That's just a design decision.
Stephan van Hulst wrote:I disagree Kurt. While it's true that unchecked exceptions are helpful in keeping code clutter free, most of the time they signify bugs.
Kurt Van Etten wrote:The only point I'm making is that an unchecked exception is only a bug if: 1) it occurs, and 2) it's uncaught. While in most circumstances one would want to ensure that the exception doesn't occur in the first place, the programmer might, as a design choice, allow an unchecked exception to occur and then catch it and deal with it.
But I might also choose to put the whole routine inside a try-catch clause. Either way, I can have the program display a message to the user that they entered an illegal expression.
Agre, but some time ago somebody pointed out there are a few xceptions to that rule, eg NumberFormatException.
Stephan van Hulst wrote:. . . I say an unchecked exception is a bug if it occurs period. . . .
Stephan van Hulst wrote: . . . bad design decisions . . .