Merge pull request #77 from techkang/patch-1
combine error handler with virtual function.
This commit is contained in:
commit
51926c2ba2
35
practical_exercises/10_day_practice/day9/异常例子/9-2.cpp
Normal file
35
practical_exercises/10_day_practice/day9/异常例子/9-2.cpp
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user