Exceptions should be thrown and not just created. An expression such as new Exception(...) does not throw the exception. You should use the keyword throw to throw the exception`.
usingSystem.Xml;classMyClass{publicvoidmyMethod(){vara=newMyException("something bad happened");}}
Compliant Code Examples
usingSystem.Xml;classMyClass{publicvoidmyMethod(){varbla=newMyClass("something bad happened");}publicvoidfoo(){Formatterformatter=languageswitch{SqlLanguage.Sql=>newStandardSqlFormatter(),SqlLanguage.Tsql=>newTSqlFormatter(),SqlLanguage.Spark=>newSparkSqlFormatter(),SqlLanguage.RedShift=>newRedshiftFormatter(),SqlLanguage.PostgreSql=>newPostgreSqlFormatter(),SqlLanguage.PlSql=>newPlSqlFormatter(),SqlLanguage.N1ql=>newN1qlFormatter(),SqlLanguage.MySql=>newMySqlFormatter(),SqlLanguage.MariaDb=>newMariaDbFormatter(),SqlLanguage.Db2=>newDb2Formatter(),_=>thrownewNotSupportedException(),};}}
usingSystem.Xml;classMyClass{publicvoidmyMethod(){thrownewMyException("something bad happened");}}
シームレスな統合。 Datadog Code Security をお試しください
Datadog Code Security
このルールを試し、Datadog Code Security でコードを解析する
このルールの使用方法
1
2
rulesets:- csharp-best-practices # Rules to enforce C# best practices.