Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Effective and Faster Debugging With Conditional Breakpoints

DZone's Guide to

Effective and Faster Debugging With Conditional Breakpoints

Check out these awesome ways to use breakpoints in Eclipse and Chrome to debug your Java and Javascript apps.

· DevOps Zone
Free Resource

The Nexus Suite is uniquely architected for a DevOps native world and creates value early in the development pipeline, provides precise contextual controls at every phase, and accelerates DevOps innovation with automation you can trust. Read how in this ebook.

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


The DevOps Zone is brought to you in partnership with Sonatype Nexus.  See how the Nexus platform infuses precise open source component intelligence into the DevOps pipeline early, everywhere, and at scale. Read how in this ebook

Topics:
effectiveness ,faster ,debugging ,debuggers ,eclipse ,chrome browser

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}