1.Exception.h 中增加ArithmetricException类
class ArithmetricException:public Exception { public: ArithmetricException():Exception(0) {} //我认为这个实现没有必要 ArithmetricException(const char* message):Exception(message) {} ArithmetricException(const char* file, int line):Exception(file, line) {} ArithmetricException(const char* message, const char* file, int line):Exception(message,file,line) {} ArithmetricException(const ArithmetricException& e):Exception(e) {} ArithmetricException& operator = (const ArithmetricException& e) { Exception::operator =(e); return *this; } };
main.cpp
#include <iostream> #include "Exception.h" using namespace std; using namespace DTLib; int main() { try { THROW_EXCEPTION(ArithmetricException,"test"); } catch(const ArithmetricException& e) { cout << " catch(const ArithmetricException& e)" << endl; cout << e.message() << endl; cout << e.location() << endl; } catch(const Exception& e) { cout << " catch(const Exception& e)" << endl; cout << e.message() << endl; cout << e.location() << endl; } return 0; }
来源:https://www.cnblogs.com/-glb/p/12037867.html