#include "debug.h" #include class Exception { public: Exception() { id=Exception::g_id++; debug("construct\n"); } static int g_id; int id; }; int Exception::g_id; class intException : public Exception { public: intException(int n) : n(n) { } int n; }; class strException : public Exception { public: strException(char *s) : s(s) { } std::string s; }; typedef void func(); void tstthrow_e() { debug("throwing Exception();\n"); throw Exception(); } void tstthrow_ie() { debug("throwing intException(123);\n"); throw intException(123); } void tstthrow_se() { debug("throwing strException('123');\n"); throw strException("123"); } void tstthrow_n_e() { debug("throwing new Exception();\n"); throw new Exception(); } void tstthrow_n_ie() { debug("throwing new intException(123);\n"); throw new intException(123); } void tstthrow_n_se() { debug("throwing new strException('123');\n"); throw new strException("123"); } void tst(func a) { try { a(); } catch(intException & e) { debug("intException & n=%d id=%d\n", e.n, e.id); } catch(strException & e) { debug("strException & s=%s id=%d\n", e.s.c_str(), e.id); } catch(Exception & e) { debug("Exception & id=%d\n", e.id); } catch(intException * e) { debug("intException * n=%d id=%d\n", e->n, e->id); } catch(strException * e) { debug("strException * s=%s id=%d\n", e->s.c_str(), e->id); } catch(Exception * e) { debug("Exception * id=%d\n", e->id); } catch (...) { debug("unknown exception *\n"); } } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { DebugSetLogfile("tstexc.log"); debug("start tstexc\n"); debug("testing tst(tstthrow_e);\n"); tst(tstthrow_e); debug("testing tst(tstthrow_ie);\n"); tst(tstthrow_ie); debug("testing tst(tstthrow_se);\n"); tst(tstthrow_se); debug("testing tst(tstthrow_n_e);\n"); tst(tstthrow_n_e); debug("testing tst(tstthrow_n_ie);\n"); tst(tstthrow_n_ie); debug("testing tst(tstthrow_n_se);\n"); tst(tstthrow_n_se); debug("end tstexc\n"); return 0; }