public void thrower() throws IllegalArgumentException {
throw new IllegalArgumentException("message");
}
results in:
- (void)thrower {
@throw new_JavaLangIllegalArgumentException_initWithNSString_(@"message");
}
But it seems that NSExceptions aren't meant to be handled from Swift code and the convention to deal with this is to make ObjC functions return nil or boolean and set an optional NSError** argument as described here:
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html
I believe this is also what was suggested here:
https://groups.google.com/forum/#!searchin/j2objc-discuss/exception|sort:date/j2objc-discuss/dSbz2J13Z-U/TeH0lXUECQAJ
The following code seems like it would convert NSException to NSError to support try-catch blocks in Swift:
https://stackoverflow.com/a/36454808
How would I do the equivalent for Java exceptions? Just replace NSException with JavaLangException?
Is there a simpler way to handle this?
Thanks again!The following code seems like it would convert NSException to NSError to support try-catch blocks in Swift:https://stackoverflow.com/a/36454808How would I do the equivalent for Java exceptions? Just replace NSException with JavaLangException?
--
You received this message because you are subscribed to the Google Groups "j2objc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to j2objc-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/j2objc-discuss/e3093572-e0c3-453f-be39-e6c4b3659eba%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "j2objc-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/j2objc-discuss/UoieAIOujHo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to j2objc-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/j2objc-discuss/CAPLadK5ZDf9Rx32JSa%3Dwx6-NdL%2BJFWA%3Da42AFd3TGKzEyaX15g%40mail.gmail.com.