使用 PyObjC 以正常方式打印 python 异常

发布于 2024-09-09 04:03:05 字数 397 浏览 14 评论 0原文

我收到这样的错误:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不吻晚风 2024-09-16 04:03:05

查看 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.

风轻花落早 2024-09-16 04:03:05

这是我自己的解决方案:

在 Objective-C 类中:

@try {
        [section loop]; //Loop through section
    } @catch (NSException *exception) {
        NSLog(@"main: Caught %@: %@", [exception name], [exception reason]);
        [self exception: [[exception userInfo] valueForKey: @"__pyobjc_exc_traceback__"]];
    }

在 python pyobjc 子类中:

def exception_(self,trace):
        traceback.print_tb(trace)
        NSApplication.sharedApplication().terminate_(None) #Accept no errors

当然,我导入了回溯模块。

Here's my own solution:

In Objective-C class:

@try {
        [section loop]; //Loop through section
    } @catch (NSException *exception) {
        NSLog(@"main: Caught %@: %@", [exception name], [exception reason]);
        [self exception: [[exception userInfo] valueForKey: @"__pyobjc_exc_traceback__"]];
    }

In python pyobjc subclass:

def exception_(self,trace):
        traceback.print_tb(trace)
        NSApplication.sharedApplication().terminate_(None) #Accept no errors

I, of-course, imported the traceback module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文