#344 Cannot completely disable default exception handler for C#


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.


  • Damon

    Damon - 2013-09-19

    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:


    Last edit: Damon 2013-09-19
  • William Fulton

    William Fulton - 2013-09-20

    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:

    %typemap(directorout) SWIGTYPE

    What you can do to if you want to keep the default typemaps is to provide this:

    %begin {
    #define SWIG_CSharpSetPendingExceptionArgument(CODE, MSG, PARAM_NAME)
    #define SWIG_CSharpSetPendingException(CODE, MSG)

    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:

    #ifndef SWIGEXCODE
    %define SWIGEXCODE "\n    if ($imclassname.SWIGPendingException.Pending) throw $imclassname.SWIGPendingException.Retrieve();" %enddef

    Then you would add a

    %begin {
    #define SWIGEXCODE 
    Last edit: William Fulton 2013-09-20

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks