4

I want to implement an automatic exception logging service which collects all exceptions/errors that are thrown all over an application. The most elegant way would be to tap into either "throw" or the actual instantiation of the Throwable.

After several hours of research I came to following conclusions:

  1. Somehow "tap into" "throw" is not possible
  2. Inject code with Instrumentation (or cglib) could solve the problem
  3. Extend the class loader and override the newInstance method could solve the problem

So far I think that option 2 would be the best choice but I fear that I am probably missing a much easier solution.

Michaël
  • 3,679
  • 7
  • 39
  • 64
jo-
  • 234
  • 1
  • 9
  • 1
    Maybe AspectJ and LTW will do the job? – hoaz Nov 28 '12 at 14:39
  • What kind of application is it? – Perception Nov 28 '12 at 14:46
  • 1
    Take a look at: http://stackoverflow.com/questions/75218/how-can-i-detect-when-an-exceptions-been-thrown-globally-in-java – jco.owens Nov 28 '12 at 14:49
  • @hoaz: Good point, I forgot to mention those in the listing. However I don't think that they have any advantages over Instrumentation, or do they?! – jo- Nov 28 '12 at 14:50
  • @jco.owens: Missed that one, thx. However this is NOT what i want. I want to know about ALL exceptions (there shouldn't be any exceptions that are not cought). – jo- Nov 28 '12 at 14:55
  • @jo-: AspectJ API is very simple, so this kind of task can be solved quickly. When you have working solution you can think about better approaches. – hoaz Nov 28 '12 at 15:03

0 Answers0