Exception handling: Difference between revisions

Content deleted Content added
Eyssant (talk | contribs)
Eyssant (talk | contribs)
Line 198:
==== Checked exceptions ====
 
The designers of Java devised<ref>{{cite web|url=https://alphacodingskills.com/java/java-exceptions.php |title=Java - Exceptions |date=Oct 2019 |chapter-urlwebsite=https://alphacodingskills.com |author=Santosh}}</ref><ref>{{cite web |url=http://answers.google.com/answers/threadview?id=26101 |title=Google Answers: The origin of checked exceptions |accessdate=2011-12-15 |url-status=live |archiveurl=http://archive.wikiwix.com/cache/20110806090553/http://answers.google.com/answers/threadview?id=26101 |archivedate=2011-08-06 }}</ref> checked exceptions,<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 a special set of exceptions. The checked exceptions that a method may raise are 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.
 
Kiniry (2006) notes however that Java's libraries (as they were in 2006) were often inconsistent in their approach to error reporting, because "Not all erroneous situations in Java are represented by exceptions though. Many methods return special values which indicate failure encoded as constant field of related classes."<ref name="Kiniry" />