[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Try-Catch block unable to catch exception
From: |
kk |
Subject: |
Try-Catch block unable to catch exception |
Date: |
Mon, 21 Jul 2008 21:16:51 -0700 (PDT) |
User-agent: |
G2/1.0 |
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.
- Try-Catch block unable to catch exception,
kk <=