Skip to content

Commit

Permalink
Merge pull request Light-City#77 from techkang/patch-1
Browse files Browse the repository at this point in the history
combine error handler with virtual function.
  • Loading branch information
Light-City committed Oct 17, 2020
2 parents afe899f + db2f1c3 commit 51926c2
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 51926c2

Please sign in to comment.