Folder icon

Tags / exceptions

UnhandledExceptionHandler in Java: how to catch uncaught exceptions

In this short tutorial, I'm going to describe how to handle uncaught exceptions in threads. This can be done by: Using threadInstance.setUncaughtExceptionHandler() ─ for a specific thread Overriding ThreadGroup's uncaughtException() method ─ for a thread group Using Thread.setDefaultUncaughtExceptionHandler() ─ for all…
Posted on

Java exceptions handling order


Uncaught exception: the image was stolen by a UFO

Consider there is a method which can throw IOException and FileNotFoundException. Is there a difference in which order we catch these exceptions in a single try-catch block? Will this code work correctly? The answer is NO. If you handle IOException first, you will never reach FileNotFoundException handling block…
Posted on