开发者

How rethrow an exception without losing the original call stack?

开发者 https://www.devze.com 2022-12-14 01:00 出处:网络
The situation is as follows: Thread A catches an exception, saves the exception\'s data somewhere in memory (using GetExceptionInformation in the exception filter), and afterwords Thread B gets that e

The situation is as follows: Thread A catches an exception, saves the exception's data somewhere in memory (using GetExceptionInformation in the exception filter), and afterwords Thread B gets that exception information and wants to rethrow it. But the thing is, when thread B rethrows the caught exception, i'm miss开发者_运维技巧ing the original call stack that lead to the exception.

How can I rethrow the exception without losing the original call stack? (note that this question is about C++).


You could unwind the stack in the catch block and save it as part of the exception you are rethrowing. Unwinding the stack in C++ is a bit tricky, but you could have a al look at the crashdump collector code that comes with WxWidgets for an example.


Question is why would you need to pass the stack to the "receiving" thread.

I assume you need the stack in order to basically report it to some error log. You can walk the stack in the catching thread, or produce a mini dump, or whatever error info you wish to collect, and then just pass a copy of the exception (if possible, beware of slicing) to the receiving thread.

0

精彩评论

暂无评论...
验证码 换一张
取 消