See Also: TypeInitializationException Members
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()