Download presentation
Presentation is loading. Please wait.
1
Ninth step for Learning C++ Programming
CLASS Virtual Functions Polymorphism Exception Handling Try-catch, throwing Nested try-catch Template
2
[ practice 1 virtual Functions ]
3
[ explain 1 virtual Functions ]
4
[ practice 1-2 virtual Functions ]
5
[ explain 1-2 virtual Functions ]
6
[ practice 2 Polymorphism (1/2) ]
7
[ practice 2 Polymorphism (2/2) ]
8
[ explain 2 Polymorphism ]
9
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
10
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
11
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
12
[ practice 3 try-catch, throwing ]
13
[ explain 3 try-catch, throwing ]
14
[ practice 4 try-catch, throwing ]
15
[ explain 4 try-catch, throwing ]
16
[ practice 5 try-catch, throwing … continue ]
17
[ practice 5 try-catch, throwing ]
18
[ explain 5 try-catch, throwing ]
19
[ practice 6 Nested try-catch ]
20
[ explain 6 Nested try-catch ]
21
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
22
[ practice 7 Exception Class – catch by reference ]
23
[ explain 7 Exception Class – catch by reference ]
24
Macro & Template
25
[ practice 8 Template ]
26
[ explain 8 Template ]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.