将信号转换为 NSException 仅在第一次有效
看来,当BSD信号转换为抛出异常时,它只在第一次起作用,而在随后的次数中不起作用。
我尝试通过在调用 NSApplicationMain 之前在 main 方法中进行的以下调用将信号转换为异常:
[[NSExceptionHandler defaultExceptionHandler] setExceptionHandlingMask:NSHandleUncaughtSystemExceptionMask];
这在第一次发生信号时确实有效。但第二次发生时,线程只是挂起,但仍然允许其他线程运行。有什么办法可以让我每次都这样吗?
顺便说一句,我通过一个按钮测试了这一点,该按钮通过写入地址零来触发 SIGSEGV 违规:
char* p = NULL;
*p = 'x';
我想要的是每次都抛出异常 - 就像 Java 的 NullPointerException 一样代码>.但目前它仅在第一次执行时有效,随后线程会挂起。
It seems that when BSD signals are converted to thrown exceptions, it only work the first time but not subsequent times.
I tried to convert signals to exception via the following call I made in the main method just before calling NSApplicationMain
:
[[NSExceptionHandler defaultExceptionHandler] setExceptionHandlingMask:NSHandleUncaughtSystemExceptionMask];
This does work the first time a signal
occurred. But the second time it happens, the thread just hangs but still allowing other threads to run. Is there any way I can make this happen each time?
Btw, I tested this by having a button that triggers a SIGSEGV
violation by writing to address zero:
char* p = NULL;
*p = 'x';
What I want is for that to throw an exception every time -- just like Java's NullPointerException
. But currently it only works the first time it is executed, subsequently the thread hangs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论