9

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?

1
  • No, there isn't an exception listener. You hava to write your own code in everhy try-catch. Commented Dec 20, 2013 at 10:36

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

What about exceptions thrown inside a clicklistener? E.g. in libgdx they runs on a new thread
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.