How come I can have
public void someMethod() {
throw new UnsupportedOperationException();
}
but not
public void someMethod() {
throw new throw new IOException();
}
The first is fine, the second generates the compile error “unhandled exception type IOException”.
All things that can be thrown are
Throwable. There are two types ofThrowable:ExceptionErrorOne subclass of
ExceptionisRuntimeException, which is “unchecked” – meaning you don’t have to declare or catch them. These are generally for “programming errors”, likeNullPointerExceptionorArrayOutOfBoundsException.Errorsare also “unchecked” and are for “unrecoverable” situations, such asOutOfMemoryErroretc.Any Throwable not a subclass of
ErrororRuntimeExceptionis “checked” and must be declared as thrown or caught.