Package gnu.mapping
Class WrappedException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- gnu.mapping.WrappedException
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
WrongType
public class WrappedException extends java.lang.RuntimeExceptionEncapsulate some Exception inside a RuntimeException. Inspired by org.xml.sax.SAXException written by David Megginson.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description WrappedException()Create a new WrappedException.WrappedException(java.lang.String message)Create a new WrappedException.WrappedException(java.lang.String message, java.lang.Throwable e)Create a new WrappedException from an existing exception.WrappedException(java.lang.Throwable e)Create a new WrappedException wrapping an existing exception.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ThrowablegetException()Return the embedded exception, if any.static java.lang.RuntimeExceptionrethrow(java.lang.Throwable ex)Re-throw as a non-checked exception.java.lang.StringtoString()Convert this exception to a string.static java.lang.RuntimeExceptionwrapIfNeeded(java.lang.Exception ex)Coerce argument to a RuntimeException.
-
-
-
Constructor Detail
-
WrappedException
public WrappedException()
Create a new WrappedException.
-
WrappedException
public WrappedException(java.lang.String message)
Create a new WrappedException.- Parameters:
message- The error or warning message.
-
WrappedException
public WrappedException(java.lang.Throwable e)
Create a new WrappedException wrapping an existing exception.The existing exception will be embedded in the new one, and its message will become the default message for the WrappedException.
- Parameters:
e- The exception to be wrapped in a WrappedException.
-
WrappedException
public WrappedException(java.lang.String message, java.lang.Throwable e)Create a new WrappedException from an existing exception.The existing exception will be embedded in the new one, but the new exception will have its own message.
- Parameters:
message- The detail message.e- The exception to be wrapped in a WrappedException.
-
-
Method Detail
-
getException
public java.lang.Throwable getException()
Return the embedded exception, if any.- Returns:
- The embedded exception, or null if there is none.
-
toString
public java.lang.String toString()
Convert this exception to a string.- Overrides:
toStringin classjava.lang.Throwable- Returns:
- A string version of this exception.
-
wrapIfNeeded
public static java.lang.RuntimeException wrapIfNeeded(java.lang.Exception ex)
Coerce argument to a RuntimeException. Using rethrow may be preferable as it doesn't require wrapping an Error.
-
rethrow
public static java.lang.RuntimeException rethrow(java.lang.Throwable ex)
Re-throw as a non-checked exception. This method never returns, in spite of the return type. This allows the call to be written as:throw WrappedExcepton.rethrow(ex)so javac and the verifier can know the code doesn't return.
-
-