3

Is there a way to be notified of caught exceptions in an eclipse application?

I know that if I start an application using eclipse debugger, I can suspend execution upon caught and uncaught exceptions (see https://stackoverflow.com/a/3066280/228965). I guess this feature somehow uses JVMTI.

Now I have the following problem:

I have an eclipse application not written by me. I want to monitor this application. I have written some bundles to monitor different aspect of the application (user interactions, workbench changes, etc..). I start these bundles along the application using bundles.info file. Now I need to be notified whenever an exception happens. I added a listener to error log and this way I am notified of uncaught exceptions. However I want also to be able to be notified of "any" exception, even those that have been caught by the original developers.

Is there a way to achieve this?

Community
  • 1
  • 1
zardosht
  • 3,014
  • 2
  • 24
  • 32
  • Would running that application in Eclipse's debugger work, or do you need a way to automatically log all exceptions from within the program? – Russell Zahniser Jan 08 '12 at 20:23
  • 2
    Use AOP to find all throws and add a `before` advice that logs. Not Eclipse-specific. – Dave Newton Jan 08 '12 at 20:27
  • I don't have the source code of the program. It is an eclipse application. I start my bundles inside the OSGi runtime of it and want to be notified upon different events, for example an exception is thrown. – zardosht Jan 18 '12 at 10:36

3 Answers3

0

Add a breakpoint to the constructors of java.lang.Exception (or maybe even Throwable, depending upon exactly what you're looking for).

All exceptions, even custom ones, must extend from one of these, so you can find each Exception as it is being created - and then even trace it through to see where it is being caught and handled (if at all).

Using AOP may also be a good option, but this approach doesn't require any modifications to the existing code - source code or byte code.

ziesemer
  • 27,712
  • 8
  • 86
  • 94
  • I am not running the program from within eclipse or in debug mode. I have given an eclipse application, and I start my own bundles in OSGi runtime of that application. There is no debugging and breakpoint. – zardosht Jan 10 '12 at 15:29
  • Is there any possibility to run it in debug mode? (You don't need Eclipse for this.) If you can't do this, then you're pretty much looking to modify the code - in which case I would suggest the AOP approach. – ziesemer Jan 10 '12 at 23:07
0

You could investigate the logger of your application. If it use log4j, you could create an appender specific for exceptions and work with them.

jenaiz
  • 547
  • 2
  • 15
-1

From JDK 1.5 you can use Thread.setDefaultUncaughtExceptionHandler() for exactly this purpose.

alexsmail
  • 5,661
  • 7
  • 37
  • 57
  • From the question: 'However I want also to be able to be notified of "any" exception, even those that have been caught by the original developers.' Your solution only handles uncaught exceptions. – Emil Lundberg Jan 08 '12 at 23:49