1

I'm stepping through some code with this kind of structure:

try {
  doSomething();
} finally {
  doAnotherThing();
  // more nested try statements down here
} 

An exception is being triggered somewhere but I don't know if it's in doSomething(). Because the code goes to the doAnotherThing() regardless of whether an exception was triggered, that tells me nothing.

Is there a visual indication somewhere when an exception is triggered? (IntelliJ 14.1.7).

2
  • Just wondering: why again are you using a version of intellij that is like years old? Commented Jul 10, 2018 at 3:19
  • That's the version that I have a licence for. Commented Jul 10, 2018 at 6:03

1 Answer 1

2

Have a look under the Run -> Breakpoints menu item. You can add (using the '+' button), 'Java Exception Breakpoints' and specify the type of exception you want to break on. After it is added, you can use 'Disabled until selected breakpoint is hit' with another breakpoint inside your try block to restrict it to the code you care about. The Breakpoints window contains a lot of useful controls for when the breakpoint is triggered.

If you need to know if an exception was thrown, it will need to be stored in code:

Throwable thrown = null; 
try {   
    //Do very important work here
} catch (ImportantException e) {
    thrown = e;
    throw e;
} finally {   
    if (thrown != null) {
        //We arrived in the finally block due to an exception
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that's very helpful. Is there a direct way to see "there is currently an exception being handled."
Unfortunately no. The closest you will get is following the methods listed in stackoverflow.com/questions/184704/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.