|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectStatic
Exceptions
public final class Exceptions
Utilities methods for dealing with exceptions. Those methods can reformat the stack
trace for console output, paint the stack trace in a Graphics2D handler, or show
the stack trace in a Swing component.
The Swing component is available only if the geotk-widgets-swing module
is available in the classpath. It looks like the following picture:

| utility/geotk-utility (download) | View source code for this class |
| Method Summary | ||
|---|---|---|
static String |
formatChainedMessages(String header,
Throwable cause)
Returns a string which contain the given message on the first line, followed by the localized message of the given exception on the next line. |
|
static String |
formatStackTrace(Throwable exception)
Returns the exception trace as a string. |
|
static void |
paintStackTrace(Graphics2D graphics,
Rectangle widgetBounds,
Throwable exception)
Writes the specified exception trace in the specified graphics context. |
|
static
|
setMessage(T exception,
String message,
boolean append)
Returns an exception of the same kind and with the same stack trace than the given exception, but with a different message. |
|
static void |
show(Component owner,
Throwable exception)
Displays an error message for the specified exception. |
|
static void |
show(Component owner,
Throwable exception,
String message)
Displays an error message for the specified exception. |
|
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T extends Throwable> T setMessage(T exception,
String message,
boolean append)
Throwable defined a setMessage(String) method.
We use this method when an external library throws an exception of the right type,
but with too few details.
This method try to create a new exception using reflection. The exception class needs
to provide a public constructor expecting a single String argument. If the
exception class does not provide such constructor, then the given exception is returned
unchanged.
T - The type of the exception.exception - The exception to copy with a different message.message - The message to set in the exception to be returned.append - If true, the existing message in the original exception (if any)
will be happened after the provided message.
Exception(String) constructor.
public static String formatChainedMessages(String header,
Throwable cause)
SQLException is handled especially in order to process the
next exception instead than the cause.
This method does not format the stack trace.
header - The message to insert on the first line, or null if none.cause - The exception, or null if none.
null if both the header was null
and no exception provide a message.public static String formatStackTrace(Throwable exception)
Throwable.printStackTrace(PrintWriter) method, then replaces the tabulation
characters by 4 white spaces.
exception - The exception to format.
public static void paintStackTrace(Graphics2D graphics,
Rectangle widgetBounds,
Throwable exception)
Component.paint(java.awt.Graphics) method
and we want to write it rather than leaving an empty window.
graphics - Graphics context in which to write exception. The graphics context shall
be in its initial state (default affine transform, default color, etc.)widgetBounds - Size of the trace which was being drawn.exception - Exception whose trace we want to write.
public static void show(Component owner,
Throwable exception)
throws UnsupportedOperationException
owner - Component in which the exception is produced, or null if unknown.exception - Exception which has been thrown and is to be reported to the user.
UnsupportedOperationException - If the geotk-widgets-swing module is
not found on the classpath.JXErrorPane
public static void show(Component owner,
Throwable exception,
String message)
throws UnsupportedOperationException
owner - Component in which the exception is produced, or null if unknown.exception - Exception which has been thrown and is to be reported to the user.message - Message to display. If this parameter is null, then
Throwable.getLocalizedMessage() will be called to obtain the message.
UnsupportedOperationException - If the geotk-widgets-swing module is
not found on the classpath.JXErrorPane
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||