Re: Which exception to use here?



Stefan Ram schrieb:
[...]
never be thrown in the first place (and if it happens:
indicate a programmer error, not a runtime failure in the
sense of a harddisk device failure or so). So:

What would be a good class to use instead of
»WhatToUseHereException« below?

java.lang.AssertionError probably if the div() method is specified to
_only_ throw the DivisionByZero exception for y == 0 and is never called
with y == 0 in the try block.

In your example you explicitly test y != 0 before calling div(). If the
DivisionByZero exception is thrown although y != 0, the div() method is
broken and there is no way to handle that without fixing that method.
.