diff --git a/SWIG/Examples/test-suite/csharp/csharp_exceptions_runme.cs b/SWIG/Examples/test-suite/csharp/csharp_exceptions_runme.cs index add2e0853..43585b106 100644 --- a/SWIG/Examples/test-suite/csharp/csharp_exceptions_runme.cs +++ b/SWIG/Examples/test-suite/csharp/csharp_exceptions_runme.cs @@ -291,6 +291,16 @@ public class runme if (testThreads[i].Failed) throw new Exception("Test Failed"); } } + + + // test inner exceptions + try { + csharp_exceptions.InnerExceptionTest(); + throw new Exception("InnerExceptionTest exception not caught"); + } catch (InvalidOperationException e) { + if (e.Message != "My OuterException message") throw new Exception("OuterException msg incorrect"); + if (e.InnerException.Message != "My InnerException message") throw new Exception("InnerException msg incorrect"); + } } public static string CRLF = "\r\n"; // Some CLR implementations use a CRLF instead of just CR } @@ -316,6 +326,8 @@ public class TestThread { throw new Exception("Exception message incorrect. Expected:\n[" + expectedMessage + "]\n" + "Received:\n[" + e.Message + "]"); if (e.ParamName != "input") throw new Exception("Exception ParamName incorrect. Expected:\n[input]\n" + "Received:\n[" + e.ParamName + "]"); + if (e.InnerException != null) + throw new Exception("Unexpected inner exception"); } if (throwsClass.dub != 1234.5678) // simple check which attempts to catch memory corruption throw new Exception("throwsException.dub = " + throwsClass.dub + " expected: 1234.5678"); diff --git a/SWIG/Examples/test-suite/csharp_exceptions.i b/SWIG/Examples/test-suite/csharp_exceptions.i index 6cc1ea5f1..bbb1a5c2f 100644 --- a/SWIG/Examples/test-suite/csharp_exceptions.i +++ b/SWIG/Examples/test-suite/csharp_exceptions.i @@ -223,3 +223,17 @@ struct ThrowsClass { } }; %} + +// test inner exceptions +%exception InnerExceptionTest() { + try { + $action + } catch(Ex &e) { + SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, e.what()); + SWIG_CSharpSetPendingException(SWIG_CSharpInvalidOperationException, "My OuterException message"); + } +} + +%inline %{ +void InnerExceptionTest() { throw Ex("My InnerException message"); } +%}