Skip to content

Commit ce679c2

Browse files
Merge pull request #80 from marinasundstrom/feature/general-exception-fix
General exception error not on invocation expr #77
2 parents eba683f + cc60761 commit ce679c2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CheckedExceptions/CheckedExceptionsAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ private void AnalyzeExceptionThrowingNode(
12021202
}
12031203

12041204
// Check for general exceptions
1205-
if (IsGeneralException(exceptionType))
1205+
if (context.Node is not InvocationExpressionSyntax && IsGeneralException(exceptionType))
12061206
{
12071207
context.ReportDiagnostic(Diagnostic.Create(RuleGeneralThrow, GetSignificantLocation(node)));
12081208
}

Test/Cases/GeneralThrowFix.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Test.Cases;
2+
3+
//C.M(); // THROW004: Throwing 'Exception' is too general; use a more specific exception type instead
4+
5+
class C
6+
{
7+
[Throws(typeof(Exception))]
8+
public static void M() { }
9+
}

0 commit comments

Comments
 (0)