org.openide.util 8.19.1

org.openide.util
Class Exceptions

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

public final class Exceptions
extends 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 Throwable>
E
attachLocalizedMessage(E e, String localizedMessage)
          Attaches additional localized message to given exception.
static
<E extends Throwable>
E
attachMessage(E e, String msg)
          Attaches additional message to given exception.
static
<E extends Throwable>
E
attachSeverity(E e, Level severity)
          Attaches a given severity to the exception.
static String findLocalizedMessage(Throwable t)
          Extracts previously attached localized message for a given throwable.
static void printStackTrace(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 Throwable> E attachMessage(E e,
                                                    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 Throwable> E attachLocalizedMessage(E e,
                                                             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

attachSeverity

public static <E extends Throwable> E attachSeverity(E e,
                                                     Level severity)
Attaches a given severity to the exception. When the exception is later passed to printStackTrace(java.lang.Throwable) method, the level is then used as a level for reported LogRecord. This allows those who report exceptions to annotate them as unimportant, expected.

Parameters:
e - exception to assign severity to
severity - the severity
Since:
8.8

findLocalizedMessage

public static String findLocalizedMessage(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(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

org.openide.util 8.19.1

Built on December 7 2011.  |  Portions Copyright 1997-2011 Oracle. All rights reserved.