Java Reference
In-Depth Information
The output is shown here.
As the output demonstrates, a
catch
for
ArithmeticException
won't catch an
ArrayIn-
dexOutOfBoundsException
.
Exceptions Enable You to Handle Errors Gracefully
One of the key benefits of exception handling is that it enables your program to respond
to an error and then continue running. For example, consider the following example that
divides the elements of one array by the elements of another. If a division by zero occurs,
an
ArithmeticException
is generated. In the program, this exception is handled by report-
ing the error and then continuing with execution. Thus, attempting to divide by zero does
not cause an abrupt run-time error resulting in the termination of the program. Instead, it is
handled gracefully, allowing program execution to continue.