Below the source code can be compromised.
exception.cpp:
extern "C" void throwInCPP() { throw 5; }
main.c
#include <stdio.h> void throwInCPP(); void throwExp(void (*callback)()) { callback(); } int main() { throwExp(throwInCPP); return 0; }
When, when it is launched, an exception will be thrown and the program will unwind the stack, trying to find the catch block, but it cannot. Then an interrupt occurs:
#0 0x00007ffff7238d67 in raise () from /usr/lib/libc.so.6
I think you can always call the cpp function that returns expc in c, but you can never put a catch block in c because it does not compile.
How is the C ++ exception handling runtime implemented? This explains how the exception works in C ++.
I really don't think throwing throw exception in c would be something good, since you can't do anything with it in the “normal” way.
source share