Skip to content

Conversation

@sirnacnud
Copy link

This PR adds support to supply a function to DJIError in order for perform a custom translation of C++ exceptions to NSException outside the library.

The reason to do this is to be able to have a better translated NSException, as the default translation doesn't use any named constants, just uses the message from the C++ exception for both the NSException name and reason.

@a4z
Copy link
Contributor

a4z commented Mar 12, 2025

This looks solid. Thank you!

Let's leave it a moment here to give others also a chance to look at it, and then merge it.
We can sync a release with the new Generator functionality in the pipeline on the generator repo.

If I am too slow, please ping me. (my workload is huge atm)

@a4z
Copy link
Contributor

a4z commented Mar 12, 2025

Do you think it would be possible for you to add a test that sets a handle pointer and checks that this gets called when an exception occurs?

@artwyman
Copy link

There's nothing wrong with this approach, but the functionality you want is already available using a different technique (or at least should be - see caveats below). In Dropbox's original use of Djinni a custom function was used which threw custom exception classes on both iOS and Android.

Note this function declaration:

[[noreturn]] attribute((weak)) void throwNSExceptionFromCurrent(const char * /ctx/) {

The weak attribute here allows this function to be replaced by a definition from some other library at link time. The weak definition in the support lib will be used only if no other definition is available.

Caveats:

  • This is obscure and was never included in the documentation - my bad.
  • I don't know if details of the linker have changed, or if the restructuring of the Djinni repos and build system since Dropbox might affect this mechanism.

I'd suggest you try defining the function throwNSExceptionFromCurrent in your own app code and see if your definition is used.

@a4z
Copy link
Contributor

a4z commented Mar 12, 2025

that still exists,

[[noreturn]] void throwNSExceptionFromCurrent(const char * ctx);

and
[[noreturn]] __attribute__((weak)) void throwNSExceptionFromCurrent(const char * /*ctx*/) {

its still the same CMake build

@sirnacnud
Copy link
Author

Thanks for the quick responses and explanation of the already existing support.

Switching to providing a custom implementation of throwNSExceptionFromCurrent did work. I wasn't aware of what this weak attribute on the function did.

@sirnacnud sirnacnud closed this Mar 13, 2025
@a4z
Copy link
Contributor

a4z commented Mar 13, 2025

  • This is obscure and was never included in the documentation - my bad.

We could possible fix that now, and add it in the docs here , need 'just' find the propper location

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.

3 participants