exception - ExceptionHandling Session 22-23 Heshaam Feili

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

View Full Document Right Arrow Icon
1 Advanced Programming-Feili Exception Handling Session 22-23 Heshaam Feili http://mehr.sharif.edu
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Advanced Programming-Feili Sessions 22 and 23 (Chapter 13): Exception Outline 13.1 Introduction 13.2 When exception handling should be used and not used 13.3 Other exception handling techniques 13.4 The basics of C++ exception handling 13.5 A simple Exception handling example: Divide by zero 13.6 – 13.7 Throwing and catching an exception 13.8 Rethrowing an exception 13.9 Exception specification 13.10 Processing unexpected exceptions 13.11 Stack unwinding example (part 1) 13.12 Constructors, destructors and exception handling 13.14 Processing new failures 13.16 Standard Library Exception Hierarchy
Background image of page 2
3 Advanced Programming-Feili 13.1 Introduction Extensibility of C++ can increase number and kinds of errors. Each new class add its own error possibilities. Exception handling enable programmers to write clearer, more robust, more fault-tolerant programs. Example of exception: memory exhaustion, subscript out of range in arrays, division by zero, arithmetic overflow,invalid function parameters. Exception is dealing with synchronous errors such as an attempt to divide by zero not for asynchronous situations such as disk I/O, mouse click. Exception handler : recovery procedure from error causing the exception In Exception handling, error will be dealt with in a different scope in which detected.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Advanced Programming-Feili 13.2 When exception handling should be used and not used To process only exceptional situations. Using exception handling mechanism for purposes other than error handling reduces performance and program clarity. To process exceptions for program components. To process exceptions from software components such as functions, libraries and classes. Offering uniform manner for handling errors in a large project.
Background image of page 4
5 Advanced Programming-Feili 13.3 Other exception handling techniques Use assert to test for coding an design errors.As we talked before it is useful at debugging time. Simply ignore exception. Could not be used for commercial products. Just for your own software! Abort the program. Good strategy for fatal errors. Inappropriate for mission-critical application. Would lead to recourse leak. Test for the error conditions, show error message and use exit to return error code to program’s environment. Use setjump(…) and longjump in < setjump . h > Immediate jump out of deeply nested function and calls back to an error handler. Unwind the stack without calling destructor for automatic objects. For some kinds of errors dedicated capabilities are exists. Use set_new_handler() to set a error handling
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Advanced Programming-Feili 13.4 The basics of C++ exception handling Used in situations in which the function that detects an error unable to deal with it.So throw an exception (raise an exception) Suspected code enclosed in a try block and one or more
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 27

exception - ExceptionHandling Session 22-23 Heshaam Feili

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

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