Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Exception Listener

Is there a way to listen any exceptions in java?

My purpose is creating a library that listens & collects all rised errors in java. Are there any way to do this?

like image 983
Eren Avatar asked Dec 20 '13 10:12

Eren


People also ask

What is a listener exception?

An exception listener allows a client to be notified of a problem asynchronously. Some connections only consume messages, so they would have no other way to learn that their connection has failed. A JMS provider should attempt to resolve connection problems itself before it notifies the client of them.

What is uncaught exception in Java?

June 01, 2022. CWE 248-Uncaught Exception occurs when an exception is not caught by a programming construct or by the programmer, it results in an uncaught exception. In Java, for example, this would be an unhandled exception that would terminate the program.


2 Answers

You can catch every uncaught exception via Thread.UncaughtExceptionHandler. If that's not sufficient I would perhaps suggest some AOP/bytecode-weaving solution to implement some watch around each created exception.

like image 164
Brian Agnew Avatar answered Oct 07 '22 13:10

Brian Agnew


I have done some thing similar using Java instrumentation API, Create java agent and Class transformer to catch hold of required Exception class and instrument the byte code as necessary

you can follow up here Using Instrumentation to record unhandled exception

Above links will give you idea of how/when to use ASM or Instrumentation

like image 28
Satheesh Cheveri Avatar answered Oct 07 '22 12:10

Satheesh Cheveri