Exceptions Not GCC

My project contains a shared library and an exe client. I found that my own exception class thrown from the library was not caught by the catch catch block, and the program ended with the message "ending the call after sending the instance ...". Continuing to play with the project, I found that any exception of any type was not caught. For example, this catch does not work:

  try
     {
         m_pSerialPort = new boost :: asio :: serial_port (m_IoService, "non-existing-port");
     }
     catch (const boost :: system :: system_error & e)
     {
         // ...
     }

Error message:

  terminate called after throwing an instance of 
 'boost :: exception_detail :: clone_impl
 <boost :: exception_detail :: error_info_injector
 <boost :: system :: system_error>> '
   what (): No such file or directory

The GCC version is 4.4.1, the Linux OS. The same code works successfully on Windows MSVC. What reason could prevent GCC from correctly recognizing exceptions?

+6
c ++ gcc exception-handling
source share
1 answer

Both .exe clients and the shared library must be linked to libgcc in order to redirect the shared library. In the GCC manual:

... if the library or the main executable should exclude or exclude exceptions, you must link it using the g ++ or GCJ driver, depending on the languages ​​used in the program, or using the -shared-libgcc option, so that it is associated with a common libgcc.

+8
source share

All Articles