Represents the error that occurs when an exception is thrown inside the
static constructor of a type.
[
Edit]
See Also:
TypeInitializationException Members
System.Object
System.Exception
System.SystemException
System.TypeInitializationException
[System.Runtime.InteropServices.ComVisible(true)] public sealed class TypeInitializationException : SystemException |
|
Thread Safety
All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.
Remarks
Example
The following example demonstrates an error that causes
a TypeInitializationException exception.
C# Example |
using System;
class TypeInit {
// Static constructor
static TypeInit () {
// Throw an application-defined exception.
throw new ApplicationException("Error in Class TypeInit");
}
public TypeInit() {}
}
class TestTypeInit {
static public void Main() {
try {
TypeInit t = new TypeInit ();
}
catch (TypeInitializationException e) {
Console.WriteLine("Error: {0}",e);
}
}
}
|
The output is
Example |
Error: System.TypeInitializationException: The type initializer for "TypeInit" threw an exception. ---> System.ApplicationException: Error in Class TypeInit
at TypeInit..cctor()
--- End of inner exception stack trace ---
at TypeInit..ctor()
at TestTypeInit.Main()
|
Requirements
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0