static void CatchAllExceptions() { try { // ThrowsExceptions.ThrowNonClsException(); } catch (Exception e) { RuntimeWrappedException rwe = e as RuntimeWrappedException; if (rwe.WrappedException is object o) { Console.WriteLine(o.ToString()); } else { // Handle other System.Exception types. } // Remove some permission. Console.Error.WriteLine("CLS compliant exception: {0}", e); } catch { // Remove the same permission as above. Console.WriteLine("Non-CLS compliant exception caught."); } }
public static void Ctor_Null() { var exception = new RuntimeWrappedException(null); Assert.NotEmpty(exception.Message); Assert.Equal(COR_E_RUNTIMEWRAPPED, exception.HResult); Assert.Null(exception.WrappedException); }
public static void Ctor_Not_Exception() { object runtimeWrappedExceptionArgument = 1; var exception = new RuntimeWrappedException(runtimeWrappedExceptionArgument); Assert.NotEmpty(exception.Message); Assert.Equal(COR_E_RUNTIMEWRAPPED, exception.HResult); Assert.Same(runtimeWrappedExceptionArgument, exception.WrappedException); }
public static void Ctor_Exception() { var wrappedException = new Exception("Created inner exception"); var exception = new RuntimeWrappedException(wrappedException); Assert.NotEmpty(exception.Message); Assert.Equal(COR_E_RUNTIMEWRAPPED, exception.HResult); Assert.Same(wrappedException, exception.WrappedException); }
public void FixtureSetUp() { Type rwet = typeof(RuntimeWrappedException); ConstructorInfo[] ctors = rwet.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic); foreach (ConstructorInfo ctor in ctors) { switch (ctor.GetParameters().Length) { case 0: // mono rwe = (RuntimeWrappedException)ctor.Invoke(null); return; case 1: // ms rwe = (RuntimeWrappedException)ctor.Invoke(new object[1] { null }); return; } } Assert.Ignore("uho, couldn't figure out RuntimeWrappedException ctor"); }