Hi, My C++ is a bit rusty, to say the least, so I picked up my ancient Stroustrup book and "derived" an example from it, see attachment range.C .
This program can be tweaked so it catches exceptions several ways. Works too, with our current toolset. The null.C example however - when used with my exception handling code - shows a dialog from my new exception handler, but never makes its way to the C++ exception handler. Running the null.C program on Linux creates a coredump too, no exception handler is called. I assumed that the goal is to have the system level exception (from use of a null pointer) be caught by the C++ exception handler. Am I wrong ? Danny -- Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
#include <iostream> using namespace std; int i, *p; void handler() { cout << "Handler" <<endl; p = &i; } main() { p = 0; try { *p = 123; } catch(...) { handler(); } cout << "Value is " << *p << endl; }
#include "iostream" #include <windows.h> using namespace std; class Vector { int *p; int sz; public: enum { max = 300 } ; class Range { }; // range exception class Size { }; // bad size exception Vector(int sz); int& operator[](int i); }; Vector::Vector(int s) { if (s < 0 || max < s) throw Size(); sz = s; // do something sensible ... } int& Vector::operator[](int i) { if (0 <= i && i <sz) return p[i]; throw Range(); } void f() { #if 1 Vector v(10); #else Vector v(1000); #endif try { cout << v[30]; } catch (Vector::Range) { MessageBoxW(0, L"Exception", L"Range handler", 0); } catch (...) { MessageBoxW(0, L"Exception", L"Generic handler", 0); } } main() { try { f(); } #if 1 catch (Vector::Size) { MessageBoxW(0, L"Exception", L"Size handler", 0); } #endif catch (...) { MessageBoxW(0, L"Exception", L"Generic handler", 0); } }
signature.asc
Description: This is a digitally signed message part
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ Cegcc-devel mailing list Cegcc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cegcc-devel