Suppose you write a class called Checking, and Checking inherits from a class called Account. Then suppose that the Checking class has a method called OrderChecks . Some code in your program creates an instance of the Checking class and calls the OrderChecks method, and gets an exception. Let's say the exception object is of type OrderChecksException . But perhaps the exception originated as the result of another exception in the Account class. Let's say that there is a $5 fee for ordering checks, and the particular account involved in the request has a balance of zero dollars (the story of my life). So the exception might have originated in Account as AccountOverdrawnException , but the OrderChecks method catches the exception and decides to throw a different exception that is specific to ordering checks ( OrderChecksException ). Instead of discarding the AccountOverdrawnException object, a developer may choose to chain the exceptions. The developer calling the OrderChecks method would then be able to catch the OrderChecksException but would also be able to obtain information about the AccountOverdrawnException and any other exceptions involved in the process of ordering checks. To navigate through an exception chain:
Tips
|