I understand that checked exceptions inherit from Exception
and that unchecked exceptions extend RuntimeException
. But looking at the source code, I can't see what's in RuntimeException that makes it unchecked.
In fact, if I make my own class called MyRuntimeException
and literally copy-paste the code from RuntimeException
(after stripping out the package declaration and changing the class name), the resulting class will be checked. That is, when I try to throw a MyRuntimeException, the compiler will complain that the exception needs to be caught or declared to be thrown. However, throwing a RuntimeException
compiles without error.
What magic pixie dust is in the built-in RuntimeException that makes it unchecked?
Edit: Is it possible for me, as an end-user programmer, to build my own Exception hierarchy and replicate the behavior of checked and unchecked exceptions?