C# exception handling improvements - they are robust and don't leak anymore. Requires typemap modifications using attribute canthrow in any unmanaged code typemaps that throw an exception and excode attribute in csout and csconstruct typemaps.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6934 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2005-02-02 22:44:32 +00:00
commit a78579ec3f
12 changed files with 288 additions and 156 deletions

View file

@ -122,6 +122,41 @@ DllExport void SWIGSTDCALL SWIGRegisterExceptionCallbacks_$module(SWIG_CSharpExc
}
static SWIGExceptionHelper exceptionHelper = new SWIGExceptionHelper();
[ThreadStatic]
private static Exception pendingException = null;
private static int numExceptionsPending = 0;
public static bool ExceptionPending {
get {
bool pending = false;
if (numExceptionsPending > 0)
if (pendingException != null)
pending = true;
return pending;
}
}
public static void SetPendingException(Exception e) {
pendingException = e;
lock(typeof($modulePINVOKE)) {
numExceptionsPending++;
}
}
public static Exception RetrievePendingException() {
Exception e = null;
if (numExceptionsPending > 0) {
if (pendingException != null) {
e = pendingException;
pendingException = null;
lock(typeof($modulePINVOKE)) {
numExceptionsPending--;
}
}
}
return e;
}
%}
%insert(runtime) %{