layout | title | tagline |
---|---|---|
page |
CC0024 |
StaticConstructorExceptionAnalyzer |
|TypeName|StaticConstructorExceptionAnalyzer | |Check Id | CC0024 | |Category | Design | |Severity | Warning |
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.
{% highlight csharp %} public class MyClass { static MyClass() { throw new System.Exception("error message"); } } {% endhighlight %}
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)
None
TBD