Class UnexpectedExceptionError

java.lang.Object
java.lang.Throwable
java.lang.Error
java.lang.AssertionError
org.tquadrat.foundation.exception.UnexpectedExceptionError
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ImpossibleExceptionError

@ClassVersion(sourceVersion="$Id: UnexpectedExceptionError.java 1060 2023-09-24 19:21:40Z tquadrat $") @API(status=STABLE, since="0.0.5") public sealed class UnexpectedExceptionError extends AssertionError permits 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:
  …
  File file = new File( … );
  if( file.exists() )
  {
      try( var inputStream = new FileInputStream( file ) )
      {
          …
      }
      catch( FileNotFoundException e )
      {
          throw new UnexpectedExceptionError( e );
      }
  }
Author:
Thomas Thrien (thomas.thrien@tquadrat.org)
Version:
$Id: UnexpectedExceptionError.java 1060 2023-09-24 19:21:40Z tquadrat $
Since:
0.0.5
See Also:
UML Diagram
UML Diagram for "org.tquadrat.foundation.exception.UnexpectedExceptionError"

UML Diagram for "org.tquadrat.foundation.exception.UnexpectedExceptionError"

UML Diagram for "org.tquadrat.foundation.exception.UnexpectedExceptionError"
  • Field Details

  • 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

      public UnexpectedExceptionError(String message, Throwable cause)
      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.