Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 An Exception is… An unusual, often unpredictable event, detectable by software or hardware, that requires special processing An exception handler is.

Similar presentations


Presentation on theme: "1 An Exception is… An unusual, often unpredictable event, detectable by software or hardware, that requires special processing An exception handler is."— Presentation transcript:

1 1 An Exception is… An unusual, often unpredictable event, detectable by software or hardware, that requires special processing An exception handler is a section of program code that is executed when a particular exception occurs.

2 2 Why have exception handlers? l With no exception handler for an exception, your program ends at the point of the exception (with no user understandable data from the O/S) l With an exception handler, you can handle the unusual condition in an understandable way

3 3 Try/Catch/Throw l Try: The block of code monitored for exceptions l Catch: The block of code following the try block handles an exception type l Throw: When an exception is detected, you throw an exception type

4 4 The try-catch Statement try Block (exception can be thrown within this block or any called functions) catch (FormalParameter1) Block catch (FormalParameter2) TryCatchStatement How one part of the program catches and processes the exception that another part of the program throws. FormalParameter DataType VariableName …

5 5 Execution of try-catch No statements throw an exception Statement following entire try-catch statement A statement throws an exception Exception Handler Statements to deal with exception are executed Control moves directly to exception handler

6 6 O/S (Unix) or you can throw exceptions l O/S thrown examples l No storage available for new request, divide by zero l User thrown exceptions l Using the throw statement


Download ppt "1 An Exception is… An unusual, often unpredictable event, detectable by software or hardware, that requires special processing An exception handler is."

Similar presentations


Ads by Google