org.openide.util
Class Exceptions

java.lang.Object
  extended by org.openide.util.Exceptions

public final class Exceptions
extends java.lang.Object

Useful utility and methods to work with exceptions as described in detail in the NetBeans logging guide. Allows to annotate exceptions with messages, extract such messages and provides a common utility method to report an exception.

Since:
7.2

Method Summary
static
<E extends java.lang.Throwable>
E
attachLocalizedMessage(E e, java.lang.String localizedMessage)
          Attaches additional localized message to given exception.
static
<E extends java.lang.Throwable>
E
attachMessage(E e, java.lang.String msg)
          Attaches additional message to given exception.
static java.lang.String findLocalizedMessage(java.lang.Throwable t)
          Extracts previously attached localized message for a given throwable.
static void printStackTrace(java.lang.Throwable t)
          Notifies an exception with a severe level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

attachMessage

public static <E extends java.lang.Throwable> E attachMessage(E e,
                                                              java.lang.String msg)
Attaches additional message to given exception. This message will be visible when one does e.printStackTrace().

Parameters:
e - exception to annotate
msg - the message to add to the exception
Returns:
the exception e

attachLocalizedMessage

public static <E extends java.lang.Throwable> E attachLocalizedMessage(E e,
                                                                       java.lang.String localizedMessage)
Attaches additional localized message to given exception. This message can be extracted later by using findLocalizedMessage(java.lang.Throwable).

Parameters:
e - exception to annotate
localizedMessage - the localized message to add to the exception
Returns:
the exception e

findLocalizedMessage

public static java.lang.String findLocalizedMessage(java.lang.Throwable t)
Extracts previously attached localized message for a given throwable. Complements attachLocalizedMessage(E, java.lang.String).

Parameters:
t - the exception to search for a message in
Returns:
localized message attached to provided exception or null if no such message has been attached

printStackTrace

public static void printStackTrace(java.lang.Throwable t)
Notifies an exception with a severe level. Such exception is going to be printed to log file and possibly also notified to alarm the user somehow.

Parameters:
t - the exception to notify