Exceptions are usually recorded during capture (and not thrown), so their consequences can also be recorded. That is, some exceptions have no consequences, therefore they do not require investigation, while other exceptions are extremely important and should be investigated whenever they occur. Therefore, a good log file should contain not only what the exception occurred, but also the impact (business) of this exception, which is known only after the exception is caught. This requires that exceptions be logged when they are processed.
Therefore, there is no Java API to catch all exceptions thrown by a running program.
However, sometimes this can help to see all thrown exceptions. You can do this by attaching a debugger to the JVM and setting an “exception checkpoint” for all subclasses of java.lang.Throwable . Alternatively, you can write an interceptor to log all exceptions that cross the API boundary (any reasonable container for dependency injection can help with this). Or you can use the Instrumentation API to add registration to classes as they are loaded.
source share