Fork me on GitHub
TypeName StaticConstructorExceptionAnalyzer
Check Id CC0024
Category Design
Severity Warning

Cause

Static constructor are called before the first time a class is used but the caller doesn’t control when exactly. Exception thrown in this context force callers to use ‘try’ block around any useage of the class and should be avoided.

Example

public class MyClass
{
	static MyClass()
	{
		throw new System.Exception("error message");
	}
}

Code fix

A code fix will be presented to you that will transform the code:

public class MyClass
{
	static MyClass()
	{
	}
}

Code fix

Related rules

None

See also

TBD