Class UnreachableCodeException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- java.lang.IllegalStateException
-
- com.saperion.common.lang.exception.UnreachableCodeException
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
FatalStateException
public class UnreachableCodeException extends java.lang.IllegalStateException
An
UnreachableCodeException
is a specializedIllegalStateException
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 exceptionpublic ... doSomething1(...) throws MyBusinessException { } public ... doSomething2(...) { try { ... = doSomething1(...); } catch (MyBusinessException e) { throw LOGGER.logThrow(new UnreachableCodeException(ExceptionFormatter.format("...", ...), e)); } }
- Author:
- agz
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
MESSAGE_HEADER
-
Constructor Summary
Constructors Constructor Description UnreachableCodeException()
Creates a newUnreachableCodeException
.UnreachableCodeException(java.lang.String message)
Creates a newUnreachableCodeException
with the specified detail message.UnreachableCodeException(java.lang.String message, java.lang.Throwable cause)
Creates a newUnreachableCodeException
with the specified detail message and cause.UnreachableCodeException(java.lang.Throwable cause)
Creates a newUnreachableCodeException
with the specified cause.
-
-
-
Field Detail
-
MESSAGE_HEADER
public static final java.lang.String MESSAGE_HEADER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UnreachableCodeException
public UnreachableCodeException()
Creates a newUnreachableCodeException
.
-
UnreachableCodeException
public UnreachableCodeException(java.lang.String message)
Creates a newUnreachableCodeException
with the specified detail message.- Parameters:
message
- detail message
-
UnreachableCodeException
public UnreachableCodeException(java.lang.String message, java.lang.Throwable cause)
Creates a newUnreachableCodeException
with the specified detail message and cause.- Parameters:
message
- detail messagecause
- cause-Throwable
of the new exception
-
UnreachableCodeException
public UnreachableCodeException(java.lang.Throwable cause)
Creates a newUnreachableCodeException
with the specified cause.- Parameters:
cause
- cause-Throwable
of the new exception
-
-