File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
practical_exercises/10_day_practice/day9/异常例子 Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments