Exception handling in Java: catch and throw again

Sometimes you catch an exception as you want to perform some logging/record some metrics as part of the process. Re-throwing the exception means you can then pass the exception higher up the call-stack so it can be dealt with by a (centralised) error handler.

Not all exceptions are unrecoverable just because they occur, so throwing an exception doesn’t necessarily cause the application to stop unless its allowed to bubble all the way up the call stack.

Catching the exception simply gives you the opportunity to decide what to do next when the exception occurs. Catching an exception and then ignoring it is typically bad practice.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top