Thursday, October 05, 2006

Conditional breakpoints

Sometimes we have to debug huge chunk of recursive code and we need to wait for a particular condition that produces problems. By just specifying a breakpoint, we may have to manually inspect the condition every time we hit the breakpoint.

This is a big waste of time if its going to be a huge process with user inputs and other processes intervening in between. Instead we can have a conditional breakpoint which suspends the thread only when a given condition is satisfied.


A conditional breakpoint has to be enabled as shown below and a condition has to be specified programmatically. For eg, the picture shows a condition breakpoint which will suspend the thread when the file being processed is "somefile.txt".

It has saved me a lot of time. If u haven't used it yet, try it. This feature is available in most of the Java IDEs like eclipse, Netbeans, IntelliJ etc.

No comments: