why was exception not handle?
C / C++ / MFC
2
Posts
2
Posters
0
Views
1
Watching
-
#include class ccc { public: ccc(int i) { m_i = i; } int m_i; }; void f(bool b) throw( ccc ) { if(b) { throw new ccc(5); } } main() { try { f(1); } catch (ccc) { std::cout<<"catch call"; abort(); } } the catch not run;
Because your not catching what you throw:
throw new ccc(5); // Here you throw a ccc* catch (ccc) // But here you catch a ccc
To fix:
// Throw like this: throw ccc(5); // Or catch like this: catch (ccc* pC) { delete pC; std::cout<<"catch call"; abort(); }
Steve