Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - checked vs unchecked Exception - tell from code alone?

Is it possible to tell if an exception class is a checked or unchecked just by looking at the code? I always thought that if it extended Exception, it was checked, but then RuntimeException extends Exception and that is unchecked. RuntimeException may be the only class that bends that rule of thumb, with other unchecked exceptions having to extend Throwable if not extending RuntimeException. However, I do not see how RuntimeException differs from Exception. I wonder if the difference is defined inside the interpreter itself?

like image 641
Michael Ford Avatar asked Mar 14 '14 12:03

Michael Ford


1 Answers

RuntimeException and its subclasses are unchecked exceptions. All others are checked exceptions.

like image 182
Kayaman Avatar answered Sep 22 '22 01:09

Kayaman