1 / 6

An Exception is…

An Exception is…. 0. 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. . Why have exception handlers?. 0.

eljah
Download Presentation

An Exception is…

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An Exception is… 0 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. Why have exception handlers? 0 • 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) • With an exception handler, you can handle the unusual condition in an understandable way

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

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

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

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

More Related