If you are using gcc 4.4.7 (and higher) on x86-64 linux , using the dwarf exception handling mechanism (which may by default), I have a way to handle this.
Suppose your inline build code is a function inline_add. It will call another function addthat may throw an exception. Here is the code:
extern "C" int add(int a, int b) {
throw "in add";
}
int inline_add(int a, int b) {
int r = 0;
__asm__ __volatile__ (
"movl %1, %%edi\n\t"
"movl %2, %%esi\n\t"
"call add\n\t"
"movl %%eax, %0\n\t"
:"=r"(r)
:"r"(a), "r"(b)
:"%eax"
);
return r;
}
inline_add :
try {
inline_add(1, 1);
} catch (...) {
std::cout << "in catch" << std::endl;
}
, gcc inline_add. , . (. " C" )
, , gcc, ,
:
void build_exception_frame(bool b) {
if (b) {
throw 0;
}
}
inline_add :
try {
inline_add(1, 1);
build_exception_frame(false);
} catch (...) {
std::cout << "in catch" << std::endl;
}
.
build_exception_frame ,
, gcc, build_exception_frame, :
void build_exception_frame(bool b) __attribute__((optimize("O0")));
, gcc .
, gcc try/catch, , .
, gcc .
- , , , . .