Class UnreachableCodeError

All Implemented Interfaces:
Serializable

public class UnreachableCodeError extends AssertionError
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: