0

When debugging JAVA 1.8 in Eclipse, if I encounter a bug in my code, I want Eclipse to break on the Exception.

Now I've added Exception to the breakpoints in Eclipse per all the normal instructions, but now when I run my program, so many exceptions are raised by frameworks just on startup that continuing past every exception is impossible.

I've worked around this so far by:

  1. Disable catch-all breakpoint on Exception
  2. Adding a single breakpoint on the first line of code in my program
  3. Run Program
  4. Enable breakpoint on Exception
  5. Continue Program

Now this has worked for skipping past the deluge of startup exceptions, but I'm now hitting the problem in other places as my program grows in size and complexity, so I have to wonder if I'm doing something fundamentally wrong.

Can I just break on errors in MY code somehow?

Robear
  • 986
  • 1
  • 11
  • 15
  • Maybe you should change your approach and first start by adding logging statements in the areas of the code where you think there might be a problem. Even if can't _catch_ the exception, the stack trace by itself should already give you a great deal of information you may use to investigate the root cause of the problem. – Tim Biegeleisen Aug 05 '18 at 15:24
  • I could, but if the IDE would just break where it encounters an error in *my* code, I wouldn't have to investigate the issue, or write excessive logging because I don't understand how to use the IDE / language well enough to just break where an error occurs. – Robear Aug 05 '18 at 15:30
  • I still feel you are doing this backwards. Run your code, crash. Check the stack trace, then add breakpoints around where the exception happened. – Tim Biegeleisen Aug 05 '18 at 15:34
  • Well, to your point, that's essentially what I'm doing right now. I'm trying to improve on that approach, however. I could save a lot of time debugging if I could just get the IDE to break on my code, hence the post :) I appreciate the input, but I seriously hope this isn't how it's normally done in Java. – Robear Aug 05 '18 at 15:38
  • 2
    How about clicking only on "uncaught locations" when you set up the breakpoint on Exception? I imagine framework exceptions would fall under the "caught locations" side of things (since they don't abort your application), while yours would be on the "uncaught locations" side (at least until you do something about them). – moilejter Aug 05 '18 at 15:59
  • I generally have at least one top-level try/catch at the program entry point, as I wouldn't ever want an exception bubbling up to the JVM in production. But I suppose I could comment that out in development, which would be a better workaround than what I currently have. This only works if the top-level try/catch is the try/catch around the code, though. I'll have to try it. – Robear Aug 05 '18 at 16:07
  • It doesn't work for my webapp :( Tomcat has a top-level try/catch I can't access. – Robear Aug 05 '18 at 16:09

0 Answers0