Content deleted Content added
No edit summary Tags: Mobile edit Mobile app edit iOS app edit App section source |
No edit summary Tags: Reverted Mobile edit Mobile app edit iOS app edit App section source |
||
Line 152:
== Checked exceptions ==
[[Java (programming language)|Java]] introduced the notion of checked exceptions,<ref>{{cite web |url=http://answers.google.com/answers/threadview?id=26101 |title=Google Answers: The origin of checked exceptions |access-date=2011-12-15 |url-status=live |archive-url=http://archive.wikiwix.com/cache/20110806090553/http://answers.google.com/answers/threadview?id=26101 |archive-date=2011-08-06 }}</ref><ref>Java Language Specification, chapter 11.2. http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html#11.2 {{webarchive|url=https://web.archive.org/web/20061208042454/http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html |date=2006-12-08 }}</ref> which are special classes of exceptions. Specifically, a checked exception extends <code>Exception</code> but does not extend <code>RuntimeException</code>. In Java, only types extending <code>Throwable</code> can be thrown and caught, and <code>Throwable</code> has two direct descendants: <code>Error</code> (indicating a serious problem a reasonable program need not catch), and <code>Exception</code>. The checked exceptions that a method may raise must be part of the method's [[Type signature|signature]]. For instance, if a method might throw an {{Java|IOException}}, it must declare this fact explicitly in its method signature. Failure to do so raises a compile-time error. This would be declared like so:
<syntaxhighlight lang="Java">
|