Sandro
Sandro

Reputation: 1276

Breakpoint that stops if statement would throw an exception

Switching from Eclipse I'm wondering if there is a possibility in IDEA to make a breakpoint that only stops if the statement on its line would throw an exception.

To achieve this in Eclipse I copy the statement into the breakpoint condition and add ; return false;. Eclipse then stops if there's an exception thrown while evaluating the breakpoint condition.

In IDEA however the condition has to be an expression. When I tried to add a semicolon, IDEA always stated the expression was invalid.

How can I achieve a similar behavior to the one I have in Eclipse or how do you work around this issue?

Upvotes: 9

Views: 633

Answers (2)

Blekit
Blekit

Reputation: 663

In Intellij IDEA you can create something called Exception breakpoints. Maybe it will fulfill your requirements. Exact procedure is described here.

You could combine it with standard Line breakpoint. For example you could add a Line Breakpoint on the line of the statement and use an option Disabled until selected breakpoint is hit and point there at the Exception Breakpoint activated by required exception class.

Upvotes: 1

jeroen_de_schutter
jeroen_de_schutter

Reputation: 1883

I handle such situations by surrounding the statement with a try/catch clause and putting the breakpoint in the catch block. It requires to recompile your code though.

Upvotes: 1

Related Questions