📄 testsystemexceptions.cs
字号:
public void TestFormatException() { ExceptionTester.CheckMain(typeof(FormatException), unchecked((int)0x80131537)); } // Test the IndexOutOfRangeException class. public void TestIndexOutOfRangeException() { ExceptionTester.CheckMain(typeof(IndexOutOfRangeException), unchecked((int)0x80131508)); } // Test the InvalidCastException class. public void TestInvalidCastException() { ExceptionTester.CheckMain(typeof(InvalidCastException), unchecked((int)0x80004002)); } // Test the InvalidOperationException class. public void TestInvalidOperationException() { ExceptionTester.CheckMain(typeof(InvalidOperationException), unchecked((int)0x80131509)); } // Test the InvalidProgramException class. public void TestInvalidProgramException() { ExceptionTester.CheckMain(typeof(InvalidProgramException), unchecked((int)0x8013153a)); } // Test the MemberAccessException class. public void TestMemberAccessException() { ExceptionTester.CheckMain(typeof(MemberAccessException), unchecked((int)0x8013151a)); } // Test the MethodAccessException class. public void TestMethodAccessException() { ExceptionTester.CheckMain(typeof(MethodAccessException), unchecked((int)0x80131510)); } // Test the MissingFieldException class. public void TestMissingFieldException() { ExceptionTester.CheckMain(typeof(MissingFieldException), unchecked((int)0x80131511)); #if !ECMA_COMPAT && CONFIG_SERIALIZATION MissingFieldException e; e = new MissingFieldException("x", "y"); SerializationInfo info = new SerializationInfo(typeof(MissingFieldException), new FormatterConverter()); StreamingContext context = new StreamingContext(); e.GetObjectData(info, context); AssertEquals("MissingFieldException (1)", "x", info.GetString("MMClassName")); AssertEquals("MissingFieldException (2)", "y", info.GetString("MMMemberName")); #endif } // Test the MissingMemberException class. public void TestMissingMemberException() { ExceptionTester.CheckMain(typeof(MissingMemberException), unchecked((int)0x80131512)); #if !ECMA_COMPAT && CONFIG_SERIALIZATION MissingMemberException e; e = new MissingMemberException("x", "y"); SerializationInfo info = new SerializationInfo(typeof(MissingMemberException), new FormatterConverter()); StreamingContext context = new StreamingContext(); e.GetObjectData(info, context); AssertEquals("MissingMemberException (1)", "x", info.GetString("MMClassName")); AssertEquals("MissingMemberException (2)", "y", info.GetString("MMMemberName")); #endif } // Test the MissingMethodException class. public void TestMissingMethodException() { ExceptionTester.CheckMain(typeof(MissingMethodException), unchecked((int)0x80131513)); #if !ECMA_COMPAT && CONFIG_SERIALIZATION MissingMethodException e; e = new MissingMethodException("x", "y"); SerializationInfo info = new SerializationInfo(typeof(MissingMethodException), new FormatterConverter()); StreamingContext context = new StreamingContext(); e.GetObjectData(info, context); AssertEquals("MissingMethodException (1)", "x", info.GetString("MMClassName")); AssertEquals("MissingMethodException (2)", "y", info.GetString("MMMemberName")); #endif } // Test the MulticastNotSupportedException class. public void TestMulticastNotSupportedException() { ExceptionTester.CheckMain (typeof(MulticastNotSupportedException), unchecked((int)0x80131514)); }#if CONFIG_EXTENDED_NUMERICS // Test the NotFiniteNumberException class. public void TestNotFiniteNumberException() { NotFiniteNumberException e; e = new NotFiniteNumberException(); AssertEquals("NotFiniteNumberException (1)", 0.0, e.OffendingNumber); AssertNotNull("NotFiniteNumberException (2)", e.Message); ExceptionTester.CheckHResult ("NotFiniteNumberException (3)", e, unchecked((int)0x80131528)); e = new NotFiniteNumberException("msg"); AssertEquals("NotFiniteNumberException (4)", 0.0, e.OffendingNumber); AssertEquals("NotFiniteNumberException (5)", "msg", e.Message); ExceptionTester.CheckHResult ("NotFiniteNumberException (6)", e, unchecked((int)0x80131528)); e = new NotFiniteNumberException("msg", 2.0); AssertEquals("NotFiniteNumberException (7)", 2.0, e.OffendingNumber); AssertEquals("NotFiniteNumberException (8)", "msg", e.Message); ExceptionTester.CheckHResult ("NotFiniteNumberException (9)", e, unchecked((int)0x80131528)); }#endif // Test the NotImplementedException class. public void TestNotImplementedException() { ExceptionTester.CheckMain(typeof(NotImplementedException), unchecked((int)0x80004001)); } // Test the NotSupportedException class. public void TestNotSupportedException() { ExceptionTester.CheckMain(typeof(NotSupportedException), unchecked((int)0x80131515)); } // Test the NullReferenceException class. public void TestNullReferenceException() { ExceptionTester.CheckMain(typeof(NullReferenceException), unchecked((int)0x80004003)); } // Test the ObjectDisposedException class. public void TestObjectDisposedException() { ObjectDisposedException e; e = new ObjectDisposedException("obj"); AssertEquals("ObjectDisposedException (1)", "obj", e.ObjectName); AssertNotNull("ObjectDisposedException (2)", e.Message); ExceptionTester.CheckHResult ("ObjectDisposedException (3)", e, unchecked((int)0x80131509)); e = new ObjectDisposedException("obj", "msg"); AssertEquals("ObjectDisposedException (4)", "obj", e.ObjectName); AssertEquals("ObjectDisposedException (5)", "obj: msg", e.Message); ExceptionTester.CheckHResult ("ObjectDisposedException (6)", e, unchecked((int)0x80131509)); e = new ObjectDisposedException(null, "msg"); AssertNull("ObjectDisposedException (7)", e.ObjectName); AssertEquals("ObjectDisposedException (8)", "msg", e.Message); ExceptionTester.CheckHResult ("ObjectDisposedException (9)", e, unchecked((int)0x80131509)); } // Test the OutOfMemoryException class. public void TestOutOfMemoryException() { ExceptionTester.CheckMain(typeof(OutOfMemoryException), unchecked((int)0x8007000e)); } // Test the OverflowException class. public void TestOverflowException() { ExceptionTester.CheckMain(typeof(OverflowException), unchecked((int)0x80131516)); }#if !ECMA_COMPAT // Test the PlatformNotSupportedException class. public void TestPlatformNotSupportedException() { ExceptionTester.CheckMain(typeof(PlatformNotSupportedException), unchecked((int)0x80131539)); }#endif // Test the RankException class. public void TestRankException() { ExceptionTester.CheckMain(typeof(RankException), unchecked((int)0x80131517)); } // Test the StackOverflowException class. public void TestStackOverflowException() { ExceptionTester.CheckMain(typeof(StackOverflowException), unchecked((int)0x800703e9)); } // Test the SystemException class. public void TestSystemException() { ExceptionTester.CheckMain(typeof(SystemException), unchecked((int)0x80131501)); }#if !ECMA_COMPAT // Test the TypeInitializationException class. public void TestTypeInitializationException() { TypeInitializationException e; e = new TypeInitializationException(null, null); AssertEquals("TypeInitializationException (1)", String.Empty, e.TypeName); AssertNotNull("TypeInitializationException (2)", e.Message); ExceptionTester.CheckHResult ("TypeInitializationException (3)", e, unchecked((int)0x80131534)); e = new TypeInitializationException("type", null); AssertEquals("TypeInitializationException (4)", "type", e.TypeName); AssertNotNull("TypeInitializationException (5)", e.Message); ExceptionTester.CheckHResult ("TypeInitializationException (6)", e, unchecked((int)0x80131534)); e = new TypeInitializationException("type", e); AssertEquals("TypeInitializationException (7)", "type", e.TypeName); AssertNotNull("TypeInitializationException (8)", e.Message); ExceptionTester.CheckHResult ("TypeInitializationException (9)", e, unchecked((int)0x80131534)); }#endif // Test the TypeLoadException class. public void TestTypeLoadException() { ExceptionTester.CheckMain(typeof(TypeLoadException), unchecked((int)0x80131522)); } // Test the TypeUnloadedException class. public void TestTypeUnloadedException() { ExceptionTester.CheckMain(typeof(TypeUnloadedException), unchecked((int)0x80131013)); } // Test the UnauthorizedAccessException class. public void TestUnauthorizedAccessException() { ExceptionTester.CheckMain(typeof(UnauthorizedAccessException), unchecked((int)0x80070005)); }}; // class TestSystemExceptions
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -