Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exception Handling. Background The fact that software modules should be robust enough to work under every situation. The exception handling mechanism.

Similar presentations


Presentation on theme: "Exception Handling. Background The fact that software modules should be robust enough to work under every situation. The exception handling mechanism."— Presentation transcript:

1 Exception Handling

2 Background The fact that software modules should be robust enough to work under every situation. The exception handling mechanism is key to achieving this goal.

3 Exception Terminology Using the exception handling mechanism in Java involves: ◦ identifying exception conditions relevant to the application; ◦ locating exception handlers to respond to potential conditions; and ◦ monitoring when such conditions occur.

4 Exception Terminology As with all representations in Java, exception conditions are denoted by objects. Similar with all objects, exceptions are also defined by class constructs, but inheriting attributes from the Exception superclass. While exception objects may be identified by object tags, additional attributes may be included for custom manipulation.

5 Exception Terminology Exception handling is dynamically enabled for statement blocks within a try block. Within it, normal facilities and rules for blocks apply but control-flow within may be transferred to associated exception handlers. An appropriate statement block prefixed by a catch-clause is then executed when the associated exception condition occurs.

6 Exception Terminology The occurrence of an exception condition is indicated by a throw- statement. It allows for an exception object to be dynamically propagated to the most recent exception handler. Flow- control does not return following a throw-statement. Instead, execution control proceeds at the statement following the try-block that handles the exception.

7 Constructs and Exception Semantics in Java We now consider the language primitives for realizing the exception handling framework in Java. As seen, ◦ exception objects are defined via class constructs that inherit from the Exception class; ◦ exception handling is enabled within a try-block, with handlers indicated by catch clauses; and ◦ an exception condition is identified by a throw statement. (Some predefined exception conditions are thrown implicitly by the Java Virtual Ma-chine.)

8 Defining Exception Objects The smallest exception object in Java merely extends from the Exception superclass,as outlined in the class definition for TransmissionError below:

9 Defining Exception Handlers Exception handlers are introduced by the catch-clause within a try-block prefix, of which the following code fragment is representative.

10 Raising Exceptions An exception condition is ultimately represented by an exception object derived from the predefined Exception class. A condition is made known by throwing an appropriate object via a throw statement, to be subsequently caught by an associated handler.


Download ppt "Exception Handling. Background The fact that software modules should be robust enough to work under every situation. The exception handling mechanism."

Similar presentations


Ads by Google