Class UnexpectedExceptionError
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ImpossibleExceptionError
This implementation of
Error
should be thrown in all cases where an unexpected exception was caught.
Unlike an
ImpossibleExceptionError,
the exception is possible, but not expected – probably because the
programmer has taken (at least thought to have …) appropriate
precautions against its occurrence. An example for this could be an
implementation of
clone()
for a particular class: with implementing that method (and declaring the
interface
Cloneable
…), instances of that class do support cloning and therefore that
exception should not be thrown. Unfortunately, changes somewhere else in
the source might prevent one of the attributes of the respective class from
being cloned, so that exception could be thrown again …
Another example could be this code sequence:
…
final var file = new File( … );
if( file.exists() )
{
try( final var inputStream = new FileInputStream( file ) )
{
…
}
catch( final FileNotFoundException e )
{
throw new UnexpectedExceptionError( e );
}
}Although the code checked that the file exists, it could have vanished unexpectedly just before it was opened.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: UnexpectedExceptionError.java 1163 2026-03-20 15:28:33Z tquadrat $
- Since:
- 0.0.5
- See Also:
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.exception.UnexpectedExceptionError"
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionUnexpectedExceptionError(String message, Throwable cause) Creates a new instance of the Error.Creates a new instance of the Error. -
Method Summary
Methods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
MSG_UnexpectedException
-
-
Constructor Details
-
UnexpectedExceptionError
Creates a new instance of the Error. The message is a constant, only the causing exception can be given.- Parameters:
cause- The causing exception.
-
UnexpectedExceptionError
Creates a new instance of the Error. This constructor should be used in cases where an enhanced message is useful or necessary.- Parameters:
message- The message for the error.cause- The causing exception.
-
