DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Java
  4. Using Java Assertions? Use an Assertion-failed Breakpoint!

Using Java Assertions? Use an Assertion-failed Breakpoint!

Zviki Cohen user avatar by
Zviki Cohen
·
May. 07, 09 · Interview
Like (0)
Save
Tweet
Share
24.78K Views

Join the DZone community and get the full member experience.

Join For Free

i'm a big fan of assertions . i use them very often in my code as safeguards. i was very pleased when true, native assertions were introduced to java: they allow adding more tests while keeping the code running faster when disabled.

if you like assertions, you will appreciate the following tip. a failed assertion will throw a java.lang.assertionerror runtime exception. logging the assertion failures is up to the application code. if your code does not report this error properly, you may completely miss the assertion failures.

eclipse has a very useful mechanism for breaking on exceptions . it's a different kind of breakpoint, which is triggered when the exception is thrown, regardless of how (and if) it is caught. if you are using assertions, i highly recommend setting a breakpoint on assertion failures when debugging your code. here's how:

  1. from the run menu, select add java exception breakpoint...
  2. type java.lang.assertionerror in the dialog box, select the exception and click ok.

that's it, you are done. from now on, the debugger will stop whenever an exception is throw. the breakpoint will appear in the breakpoints view. you can right click it and select breakpoint properties... to see all the settings you can control.

eclipse-exception-breakpoint the most useful feature would be to break on uncaught exceptions only, although, in case of assertions, i would break in any case.

needless to say, the exception breakpoints can be used for any kind of exception. truly a hidden treasure worth adding to your toolbox.
from http://blog.zvikico.com
Assertion (software development) Java (programming language)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Host Hack Attempt Detection Using ELK
  • Java REST API Frameworks
  • NoSQL vs SQL: What, Where, and How
  • The Power of Docker Images: A Comprehensive Guide to Building From Scratch

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: