|
|

|  |
Exception classes In Java, exceptions are represented as classes and form a hierarchy. The advantage of this structure is that it allows the programmer to handle groups of exceptions rather than individual cases. For example, suppose we are writing a section of program that undertakes a number of file methods (reading, writing, etc). All the classes concerned with file handling exceptions are subclasses of the class IOException . So if we want to catch all such exceptions in one catch section, we can write: { System.out.println ("Sorry, something went wrong during a file method"); }
The problem with this approach is that treating all the exceptions as equivalent may not be what we want. It probably doesnt help the user very much if the program cannot give a more detailed explanation of what is wrong. Note that all exceptions used by the Java standard classes are subclasses of Exception. So if a program catches an Exception then it guarantees to handle all possible exceptions. This is sometimes useful when developing a program, but is not normally good practice because, again, it is difficult to tell the user what has happened. Back to top 
RITSEC - Global Campus Copyright ?1999 RITSEC- Middlesex University. All rights reserved. webmaster@globalcampus.com.eg |
|