Menu

#344 Cannot completely disable default exception handler for C#

None
closed-out-of-date
nobody
5
2021-12-25
2013-09-19
Damon
No

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.

Discussion

  • Damon

    Damon - 2013-09-19

    Patch attached.

     
  • 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:

    -DSWIG_CSHARP_NO_EXCEPTION_HELPER

     

    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
    #endif
    

    Then you would add a

    %begin {
    #define SWIGEXCODE 
    %}
    
     

    Last edit: William Fulton 2013-09-20
  • Olly Betts

    Olly Betts - 2021-12-25
    • status: open --> closed-out-of-date
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2021-12-25

    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.

     

Log in to post a comment.