Prev | Current Page 225 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"

That is important to segregating code for handling different kinds of problems.
If a method throws a FileNotFoundException, it may be easy to fix by asking the operator to enter the
file name again. On the other hand, if a read of the file fails and the method throws an IOException, it may
be difficult for the program to recover. In the first case the catch block may ???soldier on,??? and in the second case
the catch block may simply report the error and then call System.exit().
When more than one catch block follows a try block, the catch blocks should be ordered such that lowerlevel
Exception classes occur before higher-level, more general classes of Exceptions. When a method
throws an exception, the try block searches down the list of catch blocks until it finds a match between the
Exception class that was thrown and the Exception class declared in the catch block. The first acceptable
match will be invoked to handle the error. If the first catch block specifies objects of class Exception, the
most general class, the first catch block will handle all Exceptions, regardless of whatever other catch
blocks there may be. So, if a program wants to attempt to recover from a FileNotFoundException and
terminate on any other failure, the catch block for the FileNotFoundException should come before the
catch block for the class Exception.


Pages:
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
śmieszne dowcipy dieta light życzenia ślubne portal Connie Talbot