This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: try-catch exception
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: vijay nag <vijunag at gmail dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 31 Oct 2013 14:59:46 +0100 (CET)
- Subject: RE: try-catch exception
- Authentication-results: sourceware.org; auth=none
- References: <CAKhyrx8PKY2CuHe=xWyCHxn4R+9kGY+1iesCjEFrVPVRaUsjbA at mail dot gmail dot com>
- Reply-to: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
On Thu, 31 Oct 2013, vijay nag wrote:
Hello-gcc,
I have a C++ library linked to C executable. C++ library is unable to
catch the exception in the try/catch block. I've also tried
"-fexceptions" compiler switch and yet the program core-dumps with
SIGABRT signal. Any reason why exception handler is being invoked ?
"terminate called after throwing an instance of 'int'
Aborted (core dumped)"
I have a sample code snippet below.
int main1 () {
try
{
throw 20;
}
catch (const exception &e)
{
cout << "An exception occurred. Exception Nr. " << e.what() << endl;
}
return 0;
}
You throw an int and try to catch a std::exception, so it isn't caught.
Try catch(int) or catch(...).
--
Marc Glisse