Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge): Catch ObjC Exceptions and throw them to JS #1043

Merged
merged 1 commit into from
Dec 28, 2018

Conversation

mbektchiev
Copy link
Contributor

refs #1029

PR Checklist

What is the current behavior?

Objective-C exceptions in calls made from JS crash the application.

What is the new behavior?

Objective-C exceptions are intercepted by iOS Runtime and are thrown to JS, where they can be caught. If no catch handler is found they will be treated as unhandled JavaScript exceptions.

@mbektchiev mbektchiev self-assigned this Dec 21, 2018
@mbektchiev mbektchiev added the bug label Dec 21, 2018
@mbektchiev mbektchiev added this to the 5.2.0 milestone Dec 21, 2018
@mbektchiev mbektchiev force-pushed the bektchiev/catch-objc-exceptions branch from 963c50a to 01c10a7 Compare December 21, 2018 17:10
* Wrap `ffi_call`s with @try-block
* Throw ObjC exception to JavaScript
(attaching the original native one as `nativeException` property)
* Update libffi with the latest master in an effort to get the
fix from libffi/libffi#418

refs #1029
@mbektchiev mbektchiev force-pushed the bektchiev/catch-objc-exceptions branch from 01c10a7 to a944466 Compare December 27, 2018 09:00
@mbektchiev mbektchiev merged commit 2d89385 into master Dec 28, 2018
@mbektchiev mbektchiev deleted the bektchiev/catch-objc-exceptions branch December 28, 2018 09:15
@farfromrefug
Copy link

@mbektchiev I can't get this to work with my native call.
I am using ios-runtime version 6.0.0-2019-05-16-165318-01
I do something like this:

try {
                const result = NTMBVectorTileDecoder.alloc().initWithCompiledStyleSet(vectorTileStyleSet);
                return result;
            } catch (err) {
                console.error('MBVectorTileDecoder error', err);
                return null;
            }

But it still crashes the app when the NSException is thrown
Screen Shot 2019-05-17 at 12 13 35
Any idea?

@mbektchiev
Copy link
Contributor Author

This happens only on Simulator due to this bug: #1044

@farfromrefug
Copy link

@mbektchiev indeed ! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants