imsavva.com

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
2017-07-05

Java exceptions handling order

showPostImage(-1069492847)

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
2016-03-19