Wednesday 25 May 2016

Effective and Faster Debugging With Conditional Breakpoints






by Sarang Nagmote



Category - Developer
More Information & Updates Available at: http://vibranttechnologies.co.in




In order to find and resolve defects that prevent correct operation of our code, we mostly use debugging process. Through this process, in a sense, we "tease out" the code and observe the values of variables in runtime. Sometimes, this life-saving process can be time consuming.
Today, most IDEs and even browsers make debugging possible. With the effective use of these tools we can make the debugging process faster and easier.
Below, I want to share some methods that help us make the debugging process fast and effective. You will see Eclipse IDE and Chrome browser samples, but you can implement these methods to other IDEs and browsers, too.
In order to debug our Java code in Eclipse, we put a breakpoint to the line which we want to observe:
Image title
When we run our code in debug mode, the execution of code suspends in every iteration of line which we put breakpoint on. We can also observe the instant values of variables, when the exceution suspends.
Image title
When we know the reason of a defect, instead of observing the instant values of variables in every iteration, we can just specify the condition in the properties of breakpoint. This makes the execution suspended only when the condition  is met. By this way, we can observe the condition we expected quickly:
Image title
Image title
Image title
With the help of this property, we can even run any code when the execution passes the breakpoint, without suspending the execution.
Image title
We can also, change the instant value of variables when the execution passes the breakpoint. So, we can prevent the case which makes a code throw exception.
Image title
With the help of this property, we can also throw any exception from the breakpoint. By this way, it is possible to observe the handling of a rare exception.
Image title
It is possible to debug this in Chrome, too. This time, we will debug our Javascript code. To do this, we can press F12 or open the "Sources" menu under Tools>Developer Tools menu and select the code which we want to debug and add breakpoint. After that, we can also specify a condition to suspend the execution only when the condition meets.
Image title

No comments:

Post a Comment