Class UnlikelyExceptionError
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ImpossibleExceptionError
This implementation of
Error
should be thrown in all cases where an unlikely exception was
caught.
Different from an
ImpossibleExceptionError,
the exception is possible, but unlikely – 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 just before it was opened.
Previously, this error was named UnexpectedExceptionError, but
the current name apparently fits better with the intention.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: UnexpectedExceptionError.java 1293 2026-10-16 13:12:15Z tquadrat $
- Since:
- 0.25.15
- See Also:
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.exception.UnlikelyExceptionError"
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionUnlikelyExceptionError(String message, Throwable cause) Creates a new instance ofUnlikelyExceptionError.UnlikelyExceptionError(Throwable cause) Creates a new instance ofUnlikelyExceptionError. -
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
-
UnlikelyExceptionError
Creates a new instance of
UnlikelyExceptionError. The message is a constant, only the causing exception can be given.- Parameters:
cause- The causing exception.
-
UnlikelyExceptionError
Creates a new instance of
UnlikelyExceptionError. 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.
-
