Is there any method to handle/catch all exceptions thrown by a Java application, without spamming costly try{}catch(Exception e){}
statements everywhere?
For example, PHP has the function set_error_handler()
.
Back story - Despite tough testing, sometimes bugs can get through, and users are always less than cooperative with helping to fix these. Ideally, I'd like to hook the application up to a web service facility that can keep track of any stack traces thrown by a user's application.
In Java SE 7 and later, we can now catch more than one type of exception in a single catch block. Each exception type that can be handled by the catch block is separated using a vertical bar or pipe | .
Java does not allow us to catch the exception twice, so we got compile-rime error at //1 .
Java allows you to catch multiple type exceptions in a single catch block. It was introduced in Java 7 and helps to optimize code. You can use vertical bar (|) to separate multiple exceptions in catch block. An old, prior to Java 7 approach to handle multiple exceptions.
In C#, You can use more than one catch block with the try block. Generally, multiple catch block is used to handle different types of exceptions means each catch block is used to handle different type of exception.
Perhaps you're looking for Thread.setDefaultUncaughtExceptionHandler()
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With