DOC PREVIEW
IUPUI CS 265 - Exception Handling

This preview shows page 1-2-3-26-27-28 out of 28 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Exception HandlingPurpose of Exception HandlingDealing with ErrorsSlide 4Slide 5Slide 6Error Handling -- Method to Cope with UncertaintiesError Handling -- Method to Cope with Uncertainties (cont)Invoking of HandlerSlide 10catch HandlersSimple Exception Handler -- ExampleAn Exception Handler Class -- ExampleSlide 14Slide 15Slide 16Throwing an ExceptionCatching an ExceptionCatching an Exception (cont)Slide 20Slide 21Rethrowing an ExceptionSlide 23Slide 24Exception specificationsProcessing Unexpected ExceptionsUsagesAcknowledgementsDale RobertsException HandlingException HandlingDale Roberts, LecturerComputer Science, IUPUIE-mail: [email protected] of Computer and Information Science,School of Science, IUPUIDale RobertsPurpose of Exception HandlingPurpose of Exception HandlingDeal with errors in an elegant manner Deal with errors in an elegant manner Write clearer, most robust, and fault tolerant Write clearer, most robust, and fault tolerant program program Error handling code Error handling code Minimum --- Casual Systems Minimum --- Casual Systems Extensive --- Commercial products Extensive --- Commercial productsDale RobertsDealing with ErrorsDealing with ErrorsErrors are interspersed throughout the software. Errors Errors are interspersed throughout the software. Errors are handled where they occur. are handled where they occur. Programmer can see the error processing near to the code and Programmer can see the error processing near to the code and determine the appropriateness of the error processing code. determine the appropriateness of the error processing code. Code becomes "polluted" with error processing. More difficult for a Code becomes "polluted" with error processing. More difficult for a programmer concerned with the application itself to read the code and programmer concerned with the application itself to read the code and determine if the code is functioning completely. determine if the code is functioning completely. User exception handling techniques User exception handling techniques Remove error code from the "main code" Remove error code from the "main code" better readability and modifiabilitybetter readability and modifiability Exception Handling – remove the error handling code Exception Handling – remove the error handling code from the “main-line” of the program’s execution – from the “main-line” of the program’s execution – improves program readability and maintainability – improves program readability and maintainability – catchcatch all kinds of exceptions, or a subset of them – programs all kinds of exceptions, or a subset of them – programs become more robustbecome more robustMemory allocation, Arithmetic Exceptions, Invalid Memory allocation, Arithmetic Exceptions, Invalid Parameters, Array Bounds, etc. – Parameters, Array Bounds, etc. – synchronous errors.synchronous errors.Dale RobertsDealing with ErrorsDealing with ErrorsUsed in situations where the system can Used in situations where the system can recover from the error causing the exception – recover from the error causing the exception – the recovery procedures is called the the recovery procedures is called the exception exception handlerhandler..Exception handling is typically used when the Exception handling is typically used when the error will be dealt with by a different part of the error will be dealt with by a different part of the program (i.e. a different scope) from where the program (i.e. a different scope) from where the error was detected.error was detected.Particularly useful for gParticularly useful for graceful degradation.raceful degradation.Use only to process exceptional situations.Use only to process exceptional situations.Dale RobertsDealing with ErrorsDealing with ErrorsTo process exceptions for program components To process exceptions for program components that are not geared to handle those exceptions that are not geared to handle those exceptions directly.directly.To process exception from software To process exception from software components, such as functions, libraries, components, such as functions, libraries, classes, etc., that are likely to be widely used classes, etc., that are likely to be widely used and where it does not make sense for those and where it does not make sense for those components to handle their own exceptions.components to handle their own exceptions.To handle error processing in a uniform manner To handle error processing in a uniform manner across large-scale projects.across large-scale projects.Use assert macro - if an assertion is false, Use assert macro - if an assertion is false, program terminates - useful at debugging program terminates - useful at debuggingDale RobertsDealing with ErrorsDealing with ErrorsIgnore exceptions! Ignore exceptions! Abort program - what if resources were Abort program - what if resources were allocated to a program and it aborted? allocated to a program and it aborted? ("Resource Leak") ("Resource Leak") Set and test error indicators - need to check Set and test error indicators - need to check them at all points in the program them at all points in the programDale RobertsError Handling -- Method to Cope with UncertaintiesError Handling -- Method to Cope with UncertaintiesA Function which Finds that it Cannot Cope With a A Function which Finds that it Cannot Cope With a Problem Throws an Exception, Hoping that Caller can Problem Throws an Exception, Hoping that Caller can Handle that Problem Handle that Problem A Function that Wants to Handle that Kind of a Problem A Function that Wants to Handle that Kind of a Problem can Indicate that it is Willing to Catch that Exception can Indicate that it is Willing to Catch that Exception Method of Transferring Control and Information to an Method of Transferring Control and Information to an Associated Exception Handler Associated Exception Handler A A trytry Block Constitutes the Section of the Program that Block Constitutes the Section of the Program that is Subject to Exception Checking is Subject to Exception Checking A Handler is Invoked with a A Handler is Invoked with a throwthrow Expression from Expression from within the within the trytry Block Block The Handler is the The Handler is the catchcatch Function FunctionDale RobertsError Handling -- Method to Cope with Uncertainties (cont)Error Handling -- Method to Cope with Uncertainties (cont)Dale RobertsInvoking of HandlerInvoking of HandlerThe


View Full Document

IUPUI CS 265 - Exception Handling

Download Exception Handling
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exception Handling and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exception Handling 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?