Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tenth step for Learning C++ Programming

Similar presentations


Presentation on theme: "Tenth step for Learning C++ Programming"— Presentation transcript:

1 Tenth step for Learning C++ Programming
Exception Handling Try-catch, throwing Nested try-catch

2 Exception Handling In a language without exception handling
Programmers are responsible for implementing some form of error detection and recovery mechanism In a language with exception handling Programs are allowed to trap specific errors by using exceptions, thereby providing the possibility of fixing the problem and continuing Exception handling separates error-handling code from other programming tasks, thus making programs easier to read and to modify. 11/2014

3 The exception handling code unit is called an exception handler
An exception is any unusual event, either erroneous or not, detectable by either hardware or software, that may require special processing The special processing that may be required after detection of an exception is called exception handling The exception handling code unit is called an exception handler

4 Exceptions are raised explicitly by the statement:
Throwing Exceptions Exceptions are raised explicitly by the statement: throw expression; The type of the expression disambiguates the intended handler 11/2014

5 [ practice 1 try-catch, throwing ]

6 [ explain 1 try-catch, throwing ]

7 [ practice 2 try-catch, throwing ]

8 [ explain 2 try-catch, throwing ]

9 [ practice 3 try-catch, throwing … continue ]

10 [ practice 3 try-catch, throwing ]

11 [ explain 3 try-catch, throwing ]

12 [ practice 4 Nested try-catch ]

13 [ explain 4 Nested try-catch ]

14 Exception Class – catch by reference
class Exception { public: int code; Exception(int i) { code = i; } }; void foo() { try { throw Exception(1); catch (Exception &e) { std::cout << e.code; No copy of the exception object 11/2014

15 [ practice 5 Exception Class – catch by reference ]

16 [ explain 5 Exception Class – catch by reference ]

17


Download ppt "Tenth step for Learning C++ Programming"

Similar presentations


Ads by Google