#860 [c#] wstring exception text should be preserved

closed-accepted
csharp (36)
5
2007-09-25
2007-09-20
David Piepgrass
No

I almost called this a bug. In std_wstring.i it says

%typemap(throws, canthrow=1) wstring
%{ (void)$1;
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "wstring exception");
return $null; %}

%typemap(throws, canthrow=1) const wstring &
%{ (void)$1;
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "wstring exception");
return $null; %}

It's throwing the message away. The exception Message given to C# should certainly be the text of the wstring. Also, the wide characters should be preserved so a new callback is needed that takes wide characters. For the time being I'm using the following workaround:

%typemap(throws, canthrow=1) wstring %{
std::string message($1.begin(), $1.end());
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, message.c_str());
return $null;
%}
%typemap(throws, canthrow=1) const wstring & %{
std::string message($1.begin(), $1.end());
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, message.c_str());
return $null;
%}

Discussion

  • Olly Betts
    Olly Betts
    2007-09-23

    • summary: wstring exception text should be preserved --> [c#] wstring exception text should be preserved
     
  • William Fulton
    William Fulton
    2007-09-25

    Logged In: YES
    user_id=242951
    Originator: NO

    Patch applied for 1.3.32, thanks.

     
  • William Fulton
    William Fulton
    2007-09-25

    • status: open --> closed-accepted