From: Tamas S. <sze...@gm...> - 2006-02-28 22:53:07
|
I was talking about passing multiple exceptions as one (nested) = exception that corresponds to the current implementation. In my case the unmanaged code may generate multiple errors stored in a global error stack within = a single function call, and I would like to forward all of the errors to = the C# code. With the current imlementation i can pass only one error per = call. But with minor modifications of csharphead.swg multiple exceptions could = be passed like (based on swig-1.3.28): ... static void SetPendingIOException(string message) { SWIGPendingException.Set(new System.IO.IOException(message, SWIGPendingException.pendingException)); ... public class SWIGPendingException { [ThreadStatic] internal static Exception pendingException =3D null; private static int numExceptionsPending =3D 0; ... public static void Set(Exception e) { pendingException =3D e; lock(typeof($imclassname)) { numExceptionsPending++; } ... } Tamas -----Original Message----- From: William S Fulton [mailto:ws...@fu...]=20 Sent: Tuesday, February 28, 2006 11:11 PM To: Tamas Szekeres Cc: swi...@li... Subject: Re: [Swig-user] Will SWIG C# support multiple exceptions to be thrown? Tamas Szekeres wrote: > Hi, >=20 > =20 >=20 > The current implementation of the C# binding passes exceptions as=20 > callbacks through a global variable. When the nat=EFve code generates = two=20 > or more exceptions within a call a new ApplicationException will be=20 > generated. >=20 > =20 >=20 > In practice it would be desirable to create nested exception instead.=20 > The previous exception could be the inner of the current. To achieve=20 > this at least csharphead.swq should be modified. I could not find a = way=20 > to redefine the swig exception mechanism without recreating it = starting=20 > from scratch. >=20 > =20 >=20 > Any suggestions will be appreciated >=20 It should not be possible to throw more than one exception per thread.=20 If you are, please post a small example showing how you do this. The=20 exceptions are stored using a thread local variable not a global=20 variable. The design was made so that more than one exception could=20 occur concurrently when more than one thread was involved, so it is=20 thread safe. There is even a testcase to check this, see the=20 csharp_exceptions.i testcase and the runtime test=20 csharp_exceptions_runme.cs. William --=20 No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.1.375 / Virus Database: 268.1.1/271 - Release Date: = 2006.02.28. =20 --=20 No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.375 / Virus Database: 268.1.1/271 - Release Date: = 2006.02.28. =20 |