2

My purpose is creating a Java library which listens and store all errors. I have caught every uncaught exception via Thread#UncaughtExceptionHandler, but when Java code has try and catch block inside the code and is not throwing exception explicitly at that time above UncaughtExceptionHandler will not work.

Ultimately what I want is a mechanism to record all caught and uncaught exceptions.

Maroun
  • 94,125
  • 30
  • 188
  • 241
Munees Majid
  • 747
  • 2
  • 8
  • 22
  • what is the goal of doing such a process? – Kick Buttowski Oct 27 '14 at 06:36
  • You'd need to do that at the JVM level (not in application code). Do you have a platform with DTrace? Otherwise probably only possible via the debugger API. – Thilo Oct 27 '14 at 06:38
  • 3
    An exception within a `try-catch` is not uncaught...it's caught, that's the point... – MadProgrammer Oct 27 '14 at 06:38
  • 1
    Here is someone doing this via bytecode instrumentation (-javaagent): http://stackoverflow.com/questions/20282619/using-instrumentation-to-record-unhandled-exception – Thilo Oct 27 '14 at 06:40
  • @KickButtowski If I had to guess, probably an application whose functions are used by non-technical people whose talents don't lie in bug reporting. I know I've wanted to get all exception data, so I had something to work with other than "it just crashed," but I can't imagine catching every exception encountered by the application is the best option. – furkle Oct 27 '14 at 06:42
  • try{ }catch(Exception e){ e.printStrackTree(); } – UtkarshBhavsar Oct 27 '14 at 06:42
  • @furkle thank you so much for your explanation, but the op had to be more clear which it was not – Kick Buttowski Oct 27 '14 at 06:44
  • @furkle - *" ... but I can't imagine catching every exception encountered by the application is the best option."* - That is an understatement! The chances are that many / most of those handled exceptions are not errors at all. If the OP has concerns about poor error reporting (or exception squashing) then using a source code analyser is a better option. – Stephen C Oct 27 '14 at 10:14

0 Answers0