Lec9 Exceptions - 9/23/2010 Todays Announcements EE422C...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
9/23/2010 1 EE422C Data Structures Sarfraz Khurshid Lecture 9 Sep 23, 2010 Today’s Announcements Today Exceptions Random numbers Polymorphism Abstract classes and interfaces Exam 1 in class on Sep 30 – next week! Exception Handling •An exception is a run-time error - you can handle it or let the JVM handle it •Exceptions can cause a program to crash OR they can be caught and handled by your program, hopefully recovering gracefully. •Exception handling - using the features of the language to manage run time errors in an orderly fashion Goals To learn how to catch exceptions To know when and where to catch an exception To learn how to throw exceptions To be able to design your own exception classes To understand the difference between checked and unchecked exceptions Why Use Exceptions? Separate normal from exceptional behavior For example, what to do if a function’s precondition is violated We want to separate Error Handling Code from Regular Code So that frequent and repetitive testing of return values, and propagation of error return values, is not required. Using exceptions may be more efficient because the normal execution path does not need to test for error conditions. Why Use Exceptions? Necessary for reliable, fault tolerant, robust software systems Often 75%+ code dedicated to reliability 20% of interface errors are errors in handling exceptions We want to manage run time errors in an orderly fashion so as to create fault tolerant software systems If an exception is not caught, the program terminates. Advanced error handling can be done that allows for resumption of execution after correcting for an error Capability to return error information is not limited to just the return type of an operation.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
9/23/2010 2 Exception Handling Options What to do about exceptions Preclude • Guarantee they do not happen Report • Up to someone else to do something Retry • Works when fault is transient Repair in situ • Fix the problem or compensate for the problem Ignore • Results are satisfactory even with the exception Why Exceptions - Details We want to propagate Errors Up the Call Stack The point at which an error occurs is rarely a suitable place to handle it, particularly in library code, but by the time an error code has been propagated to a place where it can be handled, too much contextual information has been lost. Exceptions bridge this gap - they allow specific
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/02/2010 for the course EE 322C taught by Professor Nettles during the Spring '08 term at University of Texas.

Page1 / 5

Lec9 Exceptions - 9/23/2010 Todays Announcements EE422C...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online