Getting python exceptions printed in the usual way with PyObjC

I get errors like this:

2010-07-13 20: 43: 15.131 Python [1527: 60f] main: Caught OC_PythonException :: LoginMenuSet instance has no attribute 'Play_sound'

What's wrong with this code:

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

I want the python exception to print normally with tracing and everything else.

Thank.

+3
source share
2 answers

Here is my own solution:

In the 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 a subclass of pyobjc python:

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

Of course, I imported the trace module.

-1
source

, Python - objc.setVerbose(1). PyObjC Python Python Objective-C.

+9

Source: https://habr.com/ru/post/1754487/


All Articles