Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 557
Sandro Avatar asked Apr 11 '14 12:04

Sandro


People also ask

How do I stop exception breakpoint?

Remove breakpoints For non-exception breakpoints: click the breakpoint in the gutter. For all breakpoints: from the main menu, select Run | View Breakpoints Ctrl+Shift+F8 , select the breakpoint, and click Remove Delete .

How do you set a conditional breakpoint?

To set a conditional breakpointOn the Home tab, in the Breakpoints group, choose Set/Clear Condition. In the Debugger Breakpoint Condition window, enter a condition. On the Home tab, in the Breakpoints group, choose List. In the Debugger Breakpoint List window, enter a condition in the Condition column.

What is a conditional breakpoint?

Conditional breakpoints allow you to break inside a code block when a defined expression evaluates to true. Conditional breakpoints highlight as orange instead of blue. Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression.

What is a breakpoint in debugging?

Breakpoints are one of the most important debugging techniques in your developer's toolbox. You set breakpoints wherever you want to pause debugger execution. For example, you may want to see the state of code variables or look at the call stack at a certain breakpoint.


2 Answers

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.

like image 158
jeroen_de_schutter Avatar answered Oct 06 '22 15:10

jeroen_de_schutter


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.

like image 35
Blekit Avatar answered Oct 06 '22 13:10

Blekit