Package ch.tocco.nice2.util
Class UnreachableCodeError
java.lang.Object
java.lang.Throwable
java.lang.Error
java.lang.AssertionError
ch.tocco.nice2.util.UnreachableCodeError
- All Implemented Interfaces:
Serializable
An exception indicating that some portion of code has been reached that is supposed
to be unreachable. Example uses are `switch` statements for loops that should always
return a value from within the loop.
**Example:**
```java
public String asString(MyEnum myEnum) {
switch ( myEnum ) {
case FOO:
return "foo";
case BAR:
return "bar";
default:
// MyEnum has only FOO and BAR, therefore, this code is unreachable, unless
// someone adds another enum constant
throw new UnreachableCodeException();
}
}
```
It can also be used to catch checked exceptions that cannot be thrown:
```java
public static final TOCCO_URL;
static {
try {
new URL("http://www.tocco.ch/")
}
catch ( MalformedURLException e ) {
throw new UnreachableCodeException("Hardcoded URL malformed", e);
}
}
```
- See Also:
-
Constructor Summary
ConstructorDescriptionUnreachableCodeError
(String message) UnreachableCodeError
(String message, Throwable cause) UnreachableCodeError
(Throwable cause) -
Method Summary
Modifier and TypeMethodDescriptionstatic UnreachableCodeError
static <E1 extends Throwable>
UnreachableCodeErrorstatic <E1 extends Throwable,
E2 extends Throwable>
UnreachableCodeErrorstatic <E1 extends Throwable,
E2 extends Throwable, E3 extends Throwable>
UnreachableCodeErrorstatic UnreachableCodeError
static UnreachableCodeError
unreachableCode
(String msg) static UnreachableCodeError
unreachableCode
(String format, Object... args) static UnreachableCodeError
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
UnreachableCodeError
public UnreachableCodeError() -
UnreachableCodeError
-
UnreachableCodeError
-
UnreachableCodeError
-
-
Method Details
-
initCause
-
unreachableCode
-
unreachableCode
-
unreachableCode
-
unreachableCode
-
propagate
-
propagate
public static <E1 extends Throwable> UnreachableCodeError propagate(Throwable e, Class<E1> e1) throws E1 - Throws:
E1
-
propagate
public static <E1 extends Throwable,E2 extends Throwable> UnreachableCodeError propagate(Throwable e, Class<E1> e1, Class<E2> e2) throws E1, E2 - Throws:
E1
E2
-
propagate
public static <E1 extends Throwable,E2 extends Throwable, UnreachableCodeError propagateE3 extends Throwable> (Throwable e, Class<E1> e1, Class<E2> e2, Class<E3> e3) throws E1, E2, E3 - Throws:
E1
E2
E3
-