diff --git "a/practical_exercises/10_day_practice/day9/\345\274\202\345\270\270\344\276\213\345\255\220/9-2.cpp" "b/practical_exercises/10_day_practice/day9/\345\274\202\345\270\270\344\276\213\345\255\220/9-2.cpp" new file mode 100644 index 00000000..6b9af7c1 --- /dev/null +++ "b/practical_exercises/10_day_practice/day9/\345\274\202\345\270\270\344\276\213\345\255\220/9-2.cpp" @@ -0,0 +1,35 @@ +#include +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; + } +}