Skip to content

Commit 51926c2

Browse files
authored
Merge pull request Light-City#77 from techkang/patch-1
combine error handler with virtual function.
2 parents afe899f + db2f1c3 commit 51926c2

File tree

1 file changed

+35
-0
lines changed
  • practical_exercises/10_day_practice/day9/异常例子

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
using namespace std;
3+
class BasicException
4+
{
5+
public:
6+
virtual string Where() { return "BasicException..."; }
7+
};
8+
class FileSysException : public BasicException
9+
{
10+
public:
11+
virtual string Where() { return "FileSysException..."; }
12+
};
13+
class FileNotFound : public FileSysException
14+
{
15+
public:
16+
virtual string Where() { return "FileNotFound..."; }
17+
};
18+
class DiskNotFound : public FileSysException
19+
{
20+
public:
21+
virtual string Where() { return "DiskNotFound..."; }
22+
};
23+
int main()
24+
{
25+
try
26+
{
27+
// ..... //程序代码
28+
DiskNotFound err;
29+
throw &err;
30+
}
31+
catch (BasicException *p)
32+
{
33+
cout << p->Where() << endl;
34+
}
35+
}

0 commit comments

Comments
 (0)