簡體   English   中英

_Unwind_RaiseException 示例

[英]_Unwind_RaiseException example

我正在研究 LLVM 的 libunwind 庫。 我想寫或看一個簡單的例子,它直接調用

_Unwind_Reason _Unwind_RaiseException( struct _Unwind_Exception *exception_object );

功能。 有誰知道有沒有使用這個函數的例子或者可以自己寫一個簡單的例子嗎?

有點晚了,但我想你會喜歡https://monoinfinito.wordpress.com/series/exception-handling-in-c/的鏈接,其中還包括使用上述函數的__cxa_throw()實現,引用這里逐字逐句:

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);
}

該函數本身是 AFAICT 獨立於編譯器/C++ 運行時庫的,因為它是在語言標准中指定的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM