使用 PyObjC 以正常方式打印 python 异常
我收到这样的错误:
2010-07-13 20:43:15.131 Python[1527:60f] 主要:捕获 OC_Python异常:: LoginMenuSet 实例没有属性 '播放声音'
这就是这段代码:
@try {
[section loop]; //Loop through section
} @catch (NSException *exception) {
NSLog(@"Caught %@: %@", [exception name], [exception reason]);
}
我希望正常打印 python 异常以及回溯和其他所有内容。
谢谢。
I'm getting errors like this:
2010-07-13 20:43:15.131
Python[1527:60f] main: Caught
OC_PythonException: :
LoginMenuSet instance has no attribute
'play_sound'
That's with this code:
@try {
[section loop]; //Loop through section
} @catch (NSException *exception) {
NSLog(@"Caught %@: %@", [exception name], [exception reason]);
}
I want the python exception to be printed normally with the traceback and everything else.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 Python 异常的一个技巧是调用 objc.setVerbose(1)。这使得 PyObjC 稍微更加冗长,并导致它在将异常从 Python 转换为 Objective-C 时打印 Python 堆栈跟踪。
One trick to see Python exceptions is to call
objc.setVerbose(1)
. This makes PyObjC slightly more verbose and causes it to print Python stack traces when converting exceptions from Python to Objective-C.这是我自己的解决方案:
在 Objective-C 类中:
在 python pyobjc 子类中:
当然,我导入了回溯模块。
Here's my own solution:
In Objective-C class:
In python pyobjc subclass:
I, of-course, imported the traceback module.