Java Exception Listener

前端 未结 2 1566
后悔当初
后悔当初 2020-12-20 18:23

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?

相关标签:
2条回答
  • 2020-12-20 18:59

    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

    0 讨论(0)
  • 2020-12-20 19:16

    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.

    0 讨论(0)
提交回复
热议问题