Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Eclipse Plug-in Development Beginner's Guide

You're reading from   Eclipse Plug-in Development Beginner's Guide Extend and customize Eclipse

Arrow left icon
Product type Paperback
Published in Aug 2016
Publisher
ISBN-13 9781783980697
Length 458 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Alex Blewitt Alex Blewitt
Author Profile Icon Alex Blewitt
Alex Blewitt
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Creating Your First Plug-in 2. Creating Views with SWT FREE CHAPTER 3. Creating JFace Viewers 4. Interacting with the User 5. Working with Preferences 6. Working with Resources 7. Creating Eclipse 4 Applications 8. Migrating to Eclipse 4.x 9. Styling Eclipse 4 Applications 10. Creating Features, Update Sites, Applications, and Products 11. Automated Testing of Plug-ins 12. Automated Builds with Tycho 13. Contributing to Eclipse A. Using OSGi Services to Dynamically Wire Applications B. Pop Quiz Answers Index

Time for action – catching exceptions

Although it's easy to put a breakpoint in the catch block, this is merely the location where the failure was ultimately caught, not where it was caused. The place where it was caught can often be in a completely different plug-in from where it was raised, and depending on the amount of information encoded within the exception (particularly if it has been transliterated into a different exception type) may hide the original source of the problem. Fortunately, Eclipse can handle such cases with a Java Exception Breakpoint.

  1. Introduce a bug into the execute method of the SampleHandler class, by adding the following just before the MessageDialog.openInformation() call:
    window = null;
    
  2. Click on the hello world icon.
  3. Nothing will appear to happen in the target Eclipse, but in the Console view of the host Eclipse instance, the error message should be seen:
    Caused by: java.lang.NullPointerException
      at com.packtpub.e4.hello.ui.handlers.SampleHandler.execute
      at org.eclipse.ui.internal.handlers.HandlerProxy.execute
      at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute
    
  4. Create a Java Exception Breakpoint in the Breakpoints view of the Debug perspective. The Add Java Exception Breakpoint dialog will be shown:
    Time for action – catching exceptions
  5. Enter NullPointerException in the search dialog, and click on OK.
  6. Click on the hello world icon, and the debugger will stop at the line where the exception is thrown, instead of where it is caught:
    Time for action – catching exceptions

What just happened?

The Java Exception Breakpoint stops when an exception is thrown, not when it is caught. The dialog asks for a single exception class to catch, and by default, the wizard has been pre-filled with any class whose name includes *Exception*. However, any name (or filter) can be typed into the search box, including abbreviations such as FNFE for FileNotFoundException. Wildcard patterns can also be used, which allows searching for Nu*Ex or *Unknown*.

By default, the exception breakpoint corresponds to instances of that specific class. This is useful (and quick) for exceptions such as NullPointerException, but not so useful for ones with an extensive class hierarchy, such as IOException. In this case, there is a checkbox visible on the breakpoint properties and at the bottom of the breakpoints view, which allows the capture of all Subclasses of this exception, not just of the specific class.

There are also two other checkboxes that say whether the debugger should stop when the exception is Caught or Uncaught. Both of these are selected by default; if both are deselected, then the breakpoint effectively becomes disabled. Caught means that the exception is thrown in a corresponding try/catch block, and Uncaught means that the exception is thrown without a try/catch block (this bubbles up to the method's caller).

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image