Java Reference
In-Depth Information
CHAPTER
11
Exception Handling
Exception handling is yet another fundamental aspect of Java that must be
understood before the more advanced APIs of the language can be used. This
chapter discusses how exception handling works in Java, including try/catch
blocks, the Handle or Declare Rule, declaring exceptions, throwing exceptions,
the finally keyword, and writing your own exceptions.
Overview of Exception Handling
An exception is a problem that arises during the execution of a program. An
exception can occur for many different reasons, including the following: a user
has entered invalid data, a file that needs to be opened cannot be found, a net-
work connection has been lost in the middle of communications, or the JVM
has run out of memory.
Some of these exceptions are caused by user error, others by programmer
error, and others by physical resources that have failed in some manner. In this
chapter, I will discuss the various types of exceptions, when you should throw
one, and when you should catch one (and times when you do not have a
choice), and how to write and throw your own exceptions.
329
Search WWH ::




Custom Search