Class UnreachableCodeException

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    FatalStateException

    public class UnreachableCodeException
    extends java.lang.IllegalStateException

    An UnreachableCodeException is a specialized IllegalStateException to denote a point of code that cannot be reached. If such an exception is ever thrown there is a serious coding error usually caused by an inconsistent or incomplete new code development.

    Examples: 1) Enums:

     public enum MyEnum
     {
         FIRST_CONST,
         SECOND_CONST,
         THIRD_CONST
     }
     
     public int doSomething(MyEnum value)
     {
         switch (value)
         {
             case FIRST_CONST:
             {
                 return 42;
             }
             case SECOND_CONST:
             {
                 return 4711;
             }
             case THIRD_CONST:
             {
                 return 12345;
             }
         }
     
         throw LOGGER.logThrow(new UnreachableCodeException(ExceptionFormatter.format("Unknown enum constant.", "myEnum", value)));
     }
     
    2) Exceptions that cannot occur because they are parameter-dependent and the used parameters must not produce such an exception
     public ... doSomething1(...) throws MyBusinessException 
     {
     }
     
     public ... doSomething2(...) 
     {
         try 
         {
             ... = doSomething1(...);
         }
         catch (MyBusinessException e) 
         {
             throw LOGGER.logThrow(new UnreachableCodeException(ExceptionFormatter.format("...", ...), e));
         }
     }
     

    Author:
    agz
    See Also:
    Serialized Form
    • Constructor Detail

      • UnreachableCodeException

        public UnreachableCodeException​(java.lang.String message)
        Creates a new UnreachableCodeException with the specified detail message.
        Parameters:
        message - detail message
      • UnreachableCodeException

        public UnreachableCodeException​(java.lang.String message,
                                        java.lang.Throwable cause)
        Creates a new UnreachableCodeException with the specified detail message and cause.
        Parameters:
        message - detail message
        cause - cause-Throwable of the new exception
      • UnreachableCodeException

        public UnreachableCodeException​(java.lang.Throwable cause)
        Creates a new UnreachableCodeException with the specified cause.
        Parameters:
        cause - cause-Throwable of the new exception