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

ios: improve exception handling #664

Merged
merged 2 commits into from Nov 18, 2023

Conversation

markusfisch
Copy link
Contributor

Make read() throw so C++ exceptions can be caught in Swift, so an app can't crash silently anymore when a C++ exception is thrown while trying to read a barcode.

This also adds a function to properly set a NSError from a C++ exception to avoid code duplication in ZXIBarcodeReader/Writer.

Make `read()` throw so C++ exceptions can be caught in Swift.

So an app can't crash silently anymore when a C++ exception is thrown
while trying to read a barcode.

This also adds a function to properly set a NSError from a C++
exception to avoid code duplication in ZXIBarcodeReader/Writer.
Because invalid GTIN data can lead to exceptions (e.g. from std::stoi),
in which case we don't want to discard the whole result.
@axxel
Copy link
Collaborator

axxel commented Nov 18, 2023

For my understanding: setting this NSError* to something non-nil will 'throw' an exception on the Swift side?

@markusfisch
Copy link
Contributor Author

Yes, exactly!

Here are the details on how Cocoa error parameters are converted to Swift throwing methods. Also check out how Cocoa Errors are handled in Swift.

@axxel axxel merged commit 9a1a087 into zxing-cpp:master Nov 18, 2023
10 checks passed
@markusfisch markusfisch deleted the ios_improve_exception_handling branch February 27, 2024 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants