try-catch exception

Marc Glisse marc.glisse@inria.fr
Thu Oct 31 13:59:00 GMT 2013


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



More information about the Gcc-help mailing list