Hi, I am a C programmer new to C++ and have some questions regarding exception handling. I am using:
g++ 4.01
Suse Linux 9
i486

Try-Catch blocks seem to work when I issue a throw. However, they do not catch illegal statements such as divide by zero, or segmentation faults. For example,

Code: CPP
try{
    throw 1;
}
catch (...) {
    cout<<"Exception caught!"<<endl;
}
OUTPUT: Exception caught.

HOWEVER

Code: CPP
try{
     int a=1, b=0;
     a=a/b;
}
catch (...) {
     cout<<"Exception caught!"<<endl;
}
Ends with a program termination "floating point error"

Am I missunderstanding C++ exception handling, or should the second example be caught? I've tried different complier options (-O0 and -O1), and (-fexceptions) with the same results.

Thanks,
Dan

Last edited by shabbir; 25Mar2006 at 07:08.. Reason: Use code in blocks