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:
Serializable
- Direct Known Subclasses:
FatalStateException
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:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newUnreachableCodeException.UnreachableCodeException(String message) Creates a newUnreachableCodeExceptionwith the specified detail message.UnreachableCodeException(String message, Throwable cause) Creates a newUnreachableCodeExceptionwith the specified detail message and cause.Creates a newUnreachableCodeExceptionwith the specified cause. -
Method Summary
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
MESSAGE_HEADER
- See Also:
-
-
Constructor Details
-
UnreachableCodeException
public UnreachableCodeException()Creates a newUnreachableCodeException. -
UnreachableCodeException
Creates a newUnreachableCodeExceptionwith the specified detail message.- Parameters:
message- detail message
-
UnreachableCodeException
Creates a newUnreachableCodeExceptionwith the specified detail message and cause.- Parameters:
message- detail messagecause- cause-Throwableof the new exception
-
UnreachableCodeException
Creates a newUnreachableCodeExceptionwith the specified cause.- Parameters:
cause- cause-Throwableof the new exception
-