有“扔”的在实际投掷之前写入文件 [英] having "throw" write to a file before actually throwing

查看:42
本文介绍了有“扔”的在实际投掷之前写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



嗨!


< OT,背景>

我遇到的情况是我使用两个编译器来自不同的

供应商编译我的程序。好像最近,由于

a配置错误,库冲突或我的无知,一个

的编译器我遇到了与libuwind.so相关的问题,
据我所知,
处理错误的复杂问题

异常时的堆栈。用这个

编译器编译的可执行文件在throw()之后与SEGV一起崩溃,从未到达catch(),

在它们之前通过_Unwind_ApplyVirtualRule之类的东西

死了。也许是因为throw()位于库中

并且是catch()在主程序中。

< / OT>


现在,对于C ++问题...


无论如何,在我解决这个问题之前,我想获得

a行为,如果每个throw语句写入一个日志文件,

在实际投掷之前。 。有没有一种方法可以做到这一点?


我尝试了一个丑陋的技巧,重新定义抛出类似

Assert(...),throw

然后预处理器替换单词throw。在

异常规范中也是如此。


尝试将所有投掷包装成一些throw_函数

似乎需要做很多工作。也许有一个简单的解决方案?


TIA,

- J.


Hi!

<OT, background>
I am in a situation where I use two compilers from different
vendors to compile my program. It seems that recently, due to
a misconfiguration, library conflict or my ignorance, with one
of the compilers I am having trouble related to libuwind.so,
which, to my knowledge, deals with the intricacies of unwinding
the stack upon an exception. Executables compiled with this
compiler crash with a SEGV after throw(), never reaching catch(),
going through likes of _Unwind_ApplyVirtualRule just before they
die. Perhaps it''s because throw()''s are located in a library
and are "caught()" in the main program.
</OT>

Now, for the C++ question...

Anyway, before I resolve this issue I''d like to obtain
a behaviour as-if "every throw statement wrote to a log file,
before actually throwing". Is there a kludge way to do it?

I tried an ugly trick of re#defining throw to something like
Assert(...),throw
but then the preprocessor replaces the word "throw" in
exception specifications too.

Trying to wrap all throws into some throw_ functions
seems like a lot of work. Perhaps there''s an easy solution?

TIA,
- J.

推荐答案

Jacek Dziedzic写道:
Jacek Dziedzic wrote:

嗨!

< OT,背景>
我处于某种情况我使用来自不同供应商的两个编译器来编译我的程序。最近似乎是由于配置错误,库冲突或我的无知,有一个编译器,我遇到了与libuwind.so相关的问题,
据我所知,这是交易在解除异常时堆栈的错综复杂。使用此编译器编译的可执行文件在throw()之后与SEGV崩溃,从未到达catch(),
在它们死亡之前通过_Unwind_ApplyVirtualRule。也许这是因为throw()位于一个库中
并且被catch()所有。在主程序中。
< / OT>

现在,对于C ++问题...

无论如何,在我解决这个问题之前我会喜欢获得一个行为,如果每个throw语句写入日志文件,
在实际投掷之前。有没有一种kludge方法呢?

Hi!

<OT, background>
I am in a situation where I use two compilers from different
vendors to compile my program. It seems that recently, due to
a misconfiguration, library conflict or my ignorance, with one
of the compilers I am having trouble related to libuwind.so,
which, to my knowledge, deals with the intricacies of unwinding
the stack upon an exception. Executables compiled with this
compiler crash with a SEGV after throw(), never reaching catch(),
going through likes of _Unwind_ApplyVirtualRule just before they
die. Perhaps it''s because throw()''s are located in a library
and are "caught()" in the main program.
</OT>

Now, for the C++ question...

Anyway, before I resolve this issue I''d like to obtain
a behaviour as-if "every throw statement wrote to a log file,
before actually throwing". Is there a kludge way to do it?




你可以让你要抛出的异常对象在

中构建它的那个。



You could let the exception object that you are about to throw do that in
its constructor.


Rolf Magnus写道:
Rolf Magnus wrote:
你可以让你要抛出的异常对象做那个在
它的构造函数。
You could let the exception object that you are about to throw do that in
its constructor.




这很有意思,谢谢!


- J.



That''s interesting, thanks!

- J.


Jacek Dziedzic写道:
Jacek Dziedzic wrote:
Rolf Magnus写道:
Rolf Magnus wrote:
你可以让你所关注的异常对象在
它的构造函数中抛出。
You could let the exception object that you are about to throw do that in
its constructor.



这很有意思,谢谢!



That''s interesting, thanks!




.. ..但话又说回来,如果我使用__LINE __,__ PRETTY_FUNCTION__

等等,它们会引用构造函数

的根异常对象,而不是扔。


Wh在我真正想要的是有一个记录我的来源

哪些例外情况发生时。


谢谢,

- J.



.... but then again, if I use __LINE__, __PRETTY_FUNCTION__
and things like that, they will refer to the constructor
of the root exception object, not the place of the throw.

What I really want is to have a log of where in my source
which exceptions occurred when.

thanks,
- J.


这篇关于有“扔”的在实际投掷之前写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆