Both Exception and Error share a common superclass, Throwable,
thus both can be thrown using the throw keyword.
When an Error or a subclass of Error is thrown, it's unchecked.
public class MainClass {
public static void main (String [] args) {
badMethod();
}
static void badMethod() {
doStuff();
}
static void doStuff() {
try {
throw new Error();
}
catch(Error me) {
throw me;
}
}
}
|