Tuesday, May 7, 2013

Replacing the default Exception dialog in Netbeans RCP

If you building a Netbeans RCP application and you would like to replace the current Exception dialog by a customised one. There are two ways to replace the standard “unexpected exception” window:

  1. The Lookup supports extension to the JDK's standard. It allows a module to remove class registered by another one.
    1. Implement your own java.util.logging handler  (using "@ServiceProvider(service=Handler.class)"). For example my.company.MyErrorHandler.
    2. Adding a META-INF/services for java.util.logging.Handler in your source. 
    3. Add to this file:

      #-org.netbeans.core.NbErrorManager
      my.company.MyErrorHandler

      The reason why the removal line starts with #- is to keep compatibility with JDK's implementation. The # means comment and thus JDK will not interpret the line and will not get confused by the - before class name.

      bits.netbeans.org
  2. You can superseding NbErrorManager.
    1. Implement your own java.util.logging handler 
    2. Use:

      @ServiceProvider(service=Handler.class, supersedes ={"org.netbeans.core.NbErrorManager"})")

      Geertjan's Blog