objc2swift icon indicating copy to clipboard operation
objc2swift copied to clipboard

throws syntax error on use of NS_DURING, NS_HANDLER, NS_ENDHANDLER

Open davidbuzz opened this issue 2 years ago • 3 comments

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 avatar Jul 07 '23 00:07 davidbuzz

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

davidbuzz avatar Jul 07 '23 00:07 davidbuzz

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 avatar Jul 07 '23 00:07 davidbuzz

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

davidbuzz avatar Jul 07 '23 02:07 davidbuzz