Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 859 Bytes

CC0024.md

File metadata and controls

50 lines (37 loc) · 859 Bytes
layout title tagline
page
CC0024
StaticConstructorExceptionAnalyzer

|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

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

Code fix

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

{% highlight csharp %} public class MyClass { static MyClass() { } } {% endhighlight %}

![Code fix]({{ BASE_PATH }}/assets/images/CC0024/codefix0.png)

Related rules

None

See also

TBD