Apply patch from Tom Hindle for bug 496138 plus test case.
authorJonathan Chambers <joncham@gmail.com>
Thu, 30 Apr 2009 01:40:52 +0000 (01:40 -0000)
committerJonathan Chambers <joncham@gmail.com>
Thu, 30 Apr 2009 01:40:52 +0000 (01:40 -0000)
2009-04-29 Tom Hindle <tom_hindle@sil.org>

* Marshal.cs: Improved GetExceptionForHR to return real
C# exceptions in certain cases instead of always COMException.

svn path=/trunk/mcs/; revision=133150

mcs/class/corlib/System.Runtime.InteropServices/ChangeLog
mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs
mcs/class/corlib/Test/System.Runtime.InteropServices/ChangeLog
mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs

index abc84af066a0c9eec6b8901359aebde62a71128c..7b51aa9efb0234fc8f67abf01054e5e164452373 100644 (file)
@@ -1,3 +1,8 @@
+2009-04-17 Tom Hindle <tom_hindle@sil.org>
+
+       * Marshal.cs: Improved GetExceptionForHR to return real C# exceptions in 
+       certain cases instead of always COMException.
+
 2009-02-24  Sebastien Pouliot  <sebastien@ximian.com>
 
        * SafeHandle.cs: Add default ctor in 2.1 profile (needed to compile
index ec69c53b186d5444a377b1424b265b4d8910543a..1f7530a6d0426386835e512b9bd0ba6da1963a02 100644 (file)
@@ -1128,6 +1128,17 @@ namespace System.Runtime.InteropServices
                internal
 #endif
                static Exception GetExceptionForHR (int errorCode, IntPtr errorInfo) {
+
+                       const int E_OUTOFMEMORY = unchecked ((int)0x8007000EL);
+                       const int E_INVALIDARG = unchecked ((int)0X80070057);
+                       
+                       switch (errorCode)
+                       {
+                       case E_OUTOFMEMORY:
+                               return new OutOfMemoryException ();
+                       case E_INVALIDARG:
+                               return new ArgumentException ();
+                       }
                        if (errorCode < 0)
                                return new COMException ("", errorCode);
                        return null;
index 2e9d53b3e9998ecec5fa5f626eb1c4ae1e86ecbc..b0fa2b2f210caf6d86df3de71d8c9f247c08c47d 100644 (file)
@@ -1,3 +1,7 @@
+2009-04-29  Jonathan Chambers  <joncham@gmail.com>
+
+       * MarshalTest.cs: Add test for GetExceptionForHR.
+
 2008-06-21  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * MarshalTest.cs: Added tests for GetHINSTANCE. Improved existing
index d73744f02bee525114962f320eb2d2d89b57e081..b6620d2300dbb52cde0ff07b1063d945f5209d28 100644 (file)
@@ -668,6 +668,19 @@ namespace MonoTests.System.Runtime.InteropServices
                        Marshal.FreeHGlobal (mem);
                }
 
+               [Test]
+               public void TestGetExceptionForHR ()
+               {
+                       const int E_OUTOFMEMORY = unchecked ((int) 0x8007000E);
+                       const int E_INVALIDARG = unchecked ((int) 0X80070057);
+                       
+                       Exception ex = Marshal.GetExceptionForHR (E_OUTOFMEMORY);
+                       Assert.AreEqual (typeof (OutOfMemoryException), ex.GetType (), "E_OUTOFMEMORY");
+                       
+                       ex = Marshal.GetExceptionForHR (E_INVALIDARG);
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "E_INVALIDARG");
+               }
+
                bool RunningOnUnix {
                        get {
                                int p = (int) Environment.OSVersion.Platform;