|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.openide.ErrorManager
A system of managing, annotating, and classifying errors and log messages. Rather than printing raw exceptions to the console, or popping up dialog boxes with exceptions, or implementing custom debug or logging facililities, code may use the error manager to access logging and error-reporting in a higher-level fashion. Standard error manager implementations can then provide generic ways of customizing logging levels for different components, and so on.
Especially important is the attaching of annotations such as stack traces to
exceptions, permitting you to throw an exception of a type permitted by your
API signature while safely encapsulating the root cause of the problem (in terms
of other nested exceptions). Code should use notify(Throwable)
rather
than directly printing caught exceptions, to make sure nested annotations are not lost.
Also localized messages may be annotated to exceptions so that code which can deal with a caught exception with a user-visible UI can display a polite and helpful message. Messages with no localized annotation can be handled in a default way while the details are reserved for the log file.
A simple example of usage to keep nested stacktraces:
public void doSomething () throws IOException { try { doSomethingElse (); } catch (IllegalArgumentException iae) { IOException ioe = new IOException ("did not work"); TopManager.getDefault ().getErrorManager ().annotate (ioe, iae); throw ioe; } } // ... try { foo.doSomething (); } catch (IOException ioe) { TopManager.getDefault ().getErrorManager ().notify (ioe); }
Inner Class Summary | |
static interface |
ErrorManager.Annotation
Annotation that can be attached to an error. |
Field Summary | |
static int |
ERROR
Serious problem, application may be crippled. |
static int |
EXCEPTION
Something went wrong, though it can be recovered. |
static int |
INFORMATIONAL
Message that would be useful for tracing events but which need not be a problem. |
static int |
UNKNOWN
Undefined severity. |
static int |
USER
Something the user should be aware of. |
static int |
WARNING
Something went wrong in the software, but it is continuing and the user need not be bothered. |
Constructor Summary | |
ErrorManager()
|
Method Summary | |
abstract Throwable |
annotate(Throwable t,
int severity,
String message,
String localizedMessage,
Throwable stackTrace,
Date date)
Annotates given exception with given values. |
Throwable |
annotate(Throwable t,
String localizedMessage)
Annotates given exception with given values. |
Throwable |
annotate(Throwable target,
Throwable t)
Annotates target exception with given exception. |
abstract Throwable |
attachAnnotations(Throwable t,
ErrorManager.Annotation[] arr)
Associates annotations with an exception. |
Throwable |
copyAnnotation(Throwable t,
Throwable copyFrom)
Takes annotations from one exception and associates them with another one. |
abstract ErrorManager.Annotation[] |
findAnnotations(Throwable t)
Finds annotations associated with a given exception. |
abstract ErrorManager |
getInstance(String name)
Returns an instance with given name. |
boolean |
isLoggable(int severity)
Test whether a messages with given severity will be logged in advance. |
abstract void |
log(int severity,
String s)
Logs the message to a file and (possibly) tells the user. |
void |
log(String s)
Logs the message to log file and (possibly) tells the user. |
abstract void |
notify(int severity,
Throwable t)
Prints the exception to the log file and (possibly) notifies the user. |
void |
notify(Throwable t)
Prints the exception to the log file and (possibly) notifies the user. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int UNKNOWN
public static final int INFORMATIONAL
public static final int WARNING
public static final int USER
public static final int EXCEPTION
public static final int ERROR
Constructor Detail |
public ErrorManager()
Method Detail |
public abstract Throwable attachAnnotations(Throwable t, ErrorManager.Annotation[] arr)
t
- the exceptionarr
- array of annotations (or null
)t
(as a convenience)public abstract ErrorManager.Annotation[] findAnnotations(Throwable t)
t
- the exceptionnull
public abstract Throwable annotate(Throwable t, int severity, String message, String localizedMessage, Throwable stackTrace, Date date)
t
- the exceptionseverity
- integer describing severity, e.g. EXCEPTION
date
- date or null
message
- message to attach to the exception or null
localizedMessage
- localized message for the user or null
stackTrace
- exception representing the stack trace or null
t
(as a convenience)public abstract void notify(int severity, Throwable t)
severity
- the severity to be applied to the exception (overrides default), e.g. EXCEPTION
t
- the exception to notifypublic final void notify(Throwable t)
t
- the exception to notifypublic abstract void log(int severity, String s)
severity
- the severity to be applied (overrides default)s
- the log messagepublic final void log(String s)
s
- the log messagepublic boolean isLoggable(int severity)
severity
- the severity to check, e.g. EXCEPTION
false
if the next call to log(int,String)
with this severity will
discard the messagepublic abstract ErrorManager getInstance(String name)
By convention, you can name error managers the same as packages (or classes)
they are designed to report information from.
For example, org.netbeans.modules.mymodule.ComplicatedParser
.
The error manager implementation should provide some way of configuring e.g. the logging level for error managers of different names. For example, in the basic NetBeans core implementation, you can define a system property with the same name as the future error manager (or a package prefix of it) whose value is the numeric logging level (e.g. -J-Dorg.netbeans.modules.mymodule.ComplicatedParser=0 to log everything). Other implementations may have quite different ways of configuring the error managers.
name
- the desired identifying namepublic final Throwable annotate(Throwable t, String localizedMessage)
t
- the exceptionlocalizedMessage
- localized message for the user or nullt
(as a convenience)public final Throwable annotate(Throwable target, Throwable t)
target
- the exception to be annotatedt
- the exception that will be addedtarget
(as a convenience)public final Throwable copyAnnotation(Throwable t, Throwable copyFrom)
t
- the exception to annotatecopyFrom
- exception to take annotations fromt
(as a convenience)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |