问题描述
这样做是否安全?
int foo(Display*, XErrorEvent*) {
throw 0;
}
XSetErrorHandler(foo);
我不会遇到任何麻烦?
推荐答案
X11错误处理程序是由用户提供并由Xlib调用的回调。从错误处理程序抛出的任何异常都将通过Xlib代码传播到调用Xlib(通常是XNextEvent或friends)的用户代码。
An X11 error handler is a callback provided by the user and called by Xlib. Any exception thrown from an error handler will propagate through Xlib code down to user code calling Xlib (typically XNextEvent or friends).
foo() <C++>
|
[error is detected by Xlib] <C>
|
[some more Xlib code] <C>
|
[some Xlib code] <C>
|
XNextEvent() <C>
|
main() <C++>
由于Xlib不是用C ++编写的,C ++运行时并不一定知道如何执行堆栈展开的Xlib代码。即使它通过运气管理正确解开,诸如由Xlib在调用错误处理程序之前分配的内存的资源可能会丢失。在C!
Since Xlib is not written in C++, the C++ runtime does not necessarily know how to do the stack unwinding of Xlib code. Even if it by sheer luck manages to do the unwinding correctly, resources such as memory allocated by Xlib prior to calling the error handler may be lost. There are no automatic destructors in C!
这篇关于是否安全的X的错误处理程序抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!