title: Resolving type of exception declared in Catch expression
body: <p>I have been working on some <strong>Roslyn code analyzer</strong>. My goal is to analyze exceptions and <code>Catch</code> blocks.</p>
  
  <p>I got to a situation when I am able to analyze nodes and get <code>NamedType</code> of every <code>Exception</code> possibly thrown by the node. At the same time I am able to enumerate all <code>Catch</code> blocks related to such a node.</p>
  
  <p>I need to <strong>resolve whether given <code>NamedType</code> is equal to <code>Catch</code> expression declaration</strong> or its base class.</p>
  
  <p>Illustrative code:</p>
  
  <pre><code>var typeName = "System.ArgumentNullException";
  NamedType exceptionType = _compilatorStartContext.Compilation.GetTypeByMetadataName(typeName);
  // exceptionType = NamedType System.IO.IOException
  
  var tryStatement = arg as TryStatementSyntax;
  CatchDeclarationSyntax @catch = tryStatement.Catches.First();
  var declaration = @catch.Declaration;
  // declaration = CatchDeclarationSyntax CatchDeclaration (Exception)
  // TODO: decide whether declaration can be instantiated from exceptionType
  </code></pre>