W
wrungel
Exceptions thrown by C++ function which is called by a C-function
which is called by a C++ function are not catched by outermost C++
function.
Operating system: Linux
Compiler: GNU GCC Version 4.2.1
file x.cc:
main ()
{
try {
y_func();
} catch (...) {
cout << "This line is NOT executed if _func() is compiled with C+
+ compiler";
}
}
file y.c:
y_func()
{
z_func();
}
file z.cc:
z_func()
{
throw exception;
}
Files x.cc and z.cc are compiled with C++ (GNU) compiler.
File y.c is compiled with C (GNU) compiler.
If z_func() throws, exception is not catched by main function.
Program crashes with error message: terminate called after throwing of
an instance 'of std::exception'
If y.c is compiled with C++ (GNU) compiler, exception is catched by
main function (desired behavior).
The complete source code can be downloaded here:
http://freenet-homepage.de/wrungel/exceptions.tgz
The problem is that the y_func() comes from third-party library and
can not be recompiled with C compiler.
How can I catch exceptions in main function caused by z_func()?
which is called by a C++ function are not catched by outermost C++
function.
Operating system: Linux
Compiler: GNU GCC Version 4.2.1
file x.cc:
main ()
{
try {
y_func();
} catch (...) {
cout << "This line is NOT executed if _func() is compiled with C+
+ compiler";
}
}
file y.c:
y_func()
{
z_func();
}
file z.cc:
z_func()
{
throw exception;
}
Files x.cc and z.cc are compiled with C++ (GNU) compiler.
File y.c is compiled with C (GNU) compiler.
If z_func() throws, exception is not catched by main function.
Program crashes with error message: terminate called after throwing of
an instance 'of std::exception'
If y.c is compiled with C++ (GNU) compiler, exception is catched by
main function (desired behavior).
The complete source code can be downloaded here:
http://freenet-homepage.de/wrungel/exceptions.tgz
The problem is that the y_func() comes from third-party library and
can not be recompiled with C compiler.
How can I catch exceptions in main function caused by z_func()?