okaxaki / objc2swift

Objective-C to Swift Converter
http://okaxaki.github.io/objc2swift/
ISC License
265 stars 38 forks source link

throws syntax error on use of NS_DURING, NS_HANDLER, NS_ENDHANDLER #15

Open davidbuzz opened 1 year ago

davidbuzz commented 1 year ago

https://developer.apple.com/documentation/foundation/ns_during https://gnustep.github.io/resources/documentation/Developer/Base/ProgrammingManual/manual_6.html

eg: ... NS_DURING [some code]; NS_HANDLER [some other code]; NS_ENDHANDLER ...

davidbuzz commented 1 year ago

https://bignerdranch.com/blog/error-handling-in-swift-2-0/

davidbuzz commented 1 year ago

there are normally defined in something like Foundation/NSException/NSException.h as something like ... [ this implementation is cut-n-pasted from cocotron , which is opensource on github]

#define NS_DURING                                  \
    {                                              \
        NSExceptionFrame __exceptionFrame;         \
        __NSPushExceptionFrame(&__exceptionFrame); \
        if(setjmp(__exceptionFrame.state) == 0) {

#define NS_HANDLER                                                             \
    __NSPopExceptionFrame(&__exceptionFrame);                                  \
    }                                                                          \
    else {                                                                     \
        NSException *localException = __exceptionFrame.exception;              \
        if(localException) { /* caller does not have to read localException */ \
        }

#define NS_ENDHANDLER \
    }                 \
    }

#define NS_VALUERETURN(val, type)                 \
    {                                             \
        __NSPopExceptionFrame(&__exceptionFrame); \
        return val;                               \
    }

#define NS_VOIDRETURN                             \
    {                                             \
        __NSPopExceptionFrame(&__exceptionFrame); \
        return;                                   \
    }
davidbuzz commented 1 year ago

... or using the try block equivalent here.. https://github.com/esteve/gnustep-base/blob/9929bacd86e437abf4b6e18557aac3a59768262a/Headers/Foundation/NSException.h#L333