Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Global Exception Handler

Is there a way to make a global exception-handler in Java. I want to use like this:

"When an exception is thrown somewhere in the WHOLE program, exit." 

The handler may not catch exceptions thrown in a try-catch body.

Martijn

like image 497
Martijn Courteaux Avatar asked Oct 10 '09 17:10

Martijn Courteaux


1 Answers

Use Thread.setDefaultUncaughtExceptionHandler. See Rod Hilton's "Global Exception Handling" blog post for an example.

like image 80
bobbymcr Avatar answered Sep 17 '22 16:09

bobbymcr