C# default exception handler has compatibility issues with Unity/Mono and need to be disabled in that situation. However, by giving just the preprocessor defines in swig command, the corresponding C wrapper code is still generated and cause compiler errors. They need to be handled in the Lib files.
Patch attached.
You can ignore the first sentence about the Unity Mono compatibility issue completely. The reported problem has nothing to do with that. It's just that giving the following preprocessor defines the default exception helper code is not completely removed:
-DSWIG_CSHARP_NO_EXCEPTION_HELPER
Last edit: Damon 2013-09-19
There are many more places that SWIG uses exceptions and this patch has missed them. The point of SWIG_CSHARP_NO_EXCEPTION_HELPER is to stop the generation of the C# SWIGExceptionHelper class innner class inside the intermediary class and nothing else. If you don't like the default exception handling, then you need to provide your own typemaps, such as:
What you can do to if you want to keep the default typemaps is to provide this:
then the code will compile and the net effect is what you desire.
What I might accept is a patch that allows users to provide their own EXCODE, to help use the default typemaps without exception handling, so something like this:
Then you would add a
Last edit: William Fulton 2013-09-20
William wasn't happy with the patch here. It looks like a patch for the alternative approach was never submitted, and 8 years later it seems unlikely that will change. There's a decent way to avoid the problem given here, so I think it's time to close this.
If someone wants to implement the suggested patch, please submit a PR against our github repo.