DEV Community

Cover image for Rethrowing Exceptions
Paul Ngugi
Paul Ngugi

Posted on

Rethrowing Exceptions

Java allows an exception handler to rethrow the exception if the handler cannot process the exception or simply wants to let its caller be notified of the exception.

The syntax for rethrowing an exception may look like this:

try {
statements;
}
catch (TheException ex) {
perform operations before exits;
throw ex;
}

The statement throw ex rethrows the exception to the caller so that other handlers in the caller get a chance to process the exception ex.

Top comments (0)