Site Search:

Describe the Advantages of Exception Handling


Back OCAJP


Advantage 1: Separating Error-Handling Code from "Regular" Code
Exceptions enable you to write the main flow of your code and to deal with the exceptional cases elsewhere. 


Advantage 2: Propagating Errors Up the Call Stack
A second advantage of exceptions is the ability to propagate error reporting up the call stack of methods. 


Advantage 3: Grouping and Differentiating Error Types
Because all exceptions thrown within a program are objects, the grouping or categorizing of exceptions is a natural outcome of the class hierarchy. An example of a group of related exception classes in the Java platform are those defined in java.io — IOException and its descendants. IOException is the most general and represents any type of error that can occur when performing I/O. Its descendants represent more specific errors. For example, FileNotFoundException means that a file could not be located on disk.

A method can write specific handlers that can handle a very specific exception. 



Back OCAJP