#include "debug.h" #include "stringutils.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 tstthrow_char() { debug("throwing const char*\n"); throw "constcharexc"; } typedef void (*voidfn)(); voidfn throwfuncs[]= { tstthrow_e, tstthrow_ie, tstthrow_se, tstthrow_n_e, tstthrow_n_ie, tstthrow_n_se, tstthrow_char, }; const char* thrownames[]= { "tstthrow_e", "tstthrow_ie", "tstthrow_se", "tstthrow_n_e", "tstthrow_n_ie", "tstthrow_n_se", "tstthrow_char", }; #define NTESTS (sizeof(throwfuncs)/sizeof(*throwfuncs)) 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(const char*msg) { debug("char*: %s\n", msg); } catch (...) { debug("unknown exception *\n"); } } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { DebugSetLogfile("tstexc.log"); debug("start tstexc\n"); for (unsigned i=0 ; i