2

I'm investigating the LLVM's libunwind library. I'd like to write or to look at a simple example which directly calls the

_Unwind_Reason _Unwind_RaiseException( struct _Unwind_Exception *exception_object );

function. Does any one know whether there are any examples that use this function or can write a simple example oneself?

embedc
  • 1,485
  • 1
  • 6
  • 20

1 Answers1

0

A bit late, but I'd guess you would have appreciated a link to https://monoinfinito.wordpress.com/series/exception-handling-in-c/ that also includes an implementation of __cxa_throw() using said function, quoted here verbatim:

void __cxa_throw(void* thrown_exception, struct type_info *tinfo, void (*dest)(void*))
{
    printf("__cxa_throw called\n");

    __cxa_exception *header = ((__cxa_exception *) thrown_exception - 1);
    _Unwind_RaiseException(&header->unwindHeader);

    // __cxa_throw never returns
    printf("no one handled __cxa_throw, terminate!\n");
    exit(0);
}

The function itself is AFAICT independent of the compiler/C++ runtime library since it is specified in the language standard.

stefanct
  • 2,503
  • 1
  • 28
  • 32