Skip to content

Commit

Permalink
combine error handler with virtual function.
Browse files Browse the repository at this point in the history
  • Loading branch information
techkang committed Sep 9, 2020
1 parent 9b6ac0e commit db2f1c3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions practical_exercises/10_day_practice/day9/异常例子/9-2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
using namespace std;
class BasicException
{
public:
virtual string Where() { return "BasicException..."; }
};
class FileSysException : public BasicException
{
public:
virtual string Where() { return "FileSysException..."; }
};
class FileNotFound : public FileSysException
{
public:
virtual string Where() { return "FileNotFound..."; }
};
class DiskNotFound : public FileSysException
{
public:
virtual string Where() { return "DiskNotFound..."; }
};
int main()
{
try
{
// ..... //程序代码
DiskNotFound err;
throw &err;
}
catch (BasicException *p)
{
cout << p->Where() << endl;
}
}

0 comments on commit db2f1c3

Please sign in to comment.