Hi -
The following piece of code does not catch the exception when compiled
and executed on Linux based systems.
    - Compiled using g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-9)
    - Platform: CentOS 4.5

[code]

#include <iostream>
#include <exception>
#include <string>

using namespace std;

int main()
{
        char *str = 0;

        try
        {
//              int i = 0;
//              int j = 1/i; // Uncommenting this would not go into
catch block. But gives "Floating Point Exception"
                strstr(str,"hello"); // str is NULL -> exception!
        }
        catch (...)
        {
                cout<<"Error!"<<endl;
        }
}
[/code]

Compiled as
    [prompt]$ g++ except.cpp


Questions:
1) Are there any compiler/linker flags to be added?
    - Info: I tried with -fexceptions and -fnon-call-exceptions flags
2) Is there any other way to catch All Exceptions?

Similar code was tried using VC++ on a windows system. It works. i.e,
control  does move to the catch block and execute as expected.
_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to