private static void AnalyzeCatchClause(SyntaxNodeAnalysisContext context) { var catchClause = (CatchClauseSyntax)context.Node; CatchDeclarationSyntax declaration = catchClause.Declaration; if (declaration == null) { return; } SemanticModel semanticModel = context.SemanticModel; CancellationToken cancellationToken = context.CancellationToken; ILocalSymbol symbol = semanticModel.GetDeclaredSymbol(declaration, cancellationToken); if (symbol?.IsErrorType() != false) { return; } ExpressionSyntax expression = null; Walker walker = null; try { walker = Walker.GetInstance(); walker.Symbol = symbol; walker.SemanticModel = semanticModel; walker.CancellationToken = cancellationToken; walker.VisitBlock(catchClause.Block); expression = walker.ThrowStatement?.Expression; } finally { if (walker != null) { Walker.Free(walker); } } if (expression != null) { DiagnosticHelpers.ReportDiagnostic( context, DiagnosticRules.RemoveOriginalExceptionFromThrowStatement, expression); } }