Exception Handling and Inheritance In inheritance, while throwing exceptions of derived classes, care should be taken that catch blocks with base type should be written after the catch block with derived type. Otherwise, the catch block with base type catches the exceptions of derived class types too. Consider the following example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #include<iostream> using namespace std; class Base {}; class Derived : public Base {}; int main() { try { throw Derived(); } catch(Base b) {
The post How to work with exceptions and inheritance in c++ appeared first on Coding Security.
How to work with exceptions and inheritance in c++
read more
Tidak ada komentar:
Posting Komentar