title: PowerShell catching typed exceptions
body: <p>I'm having an issue with PowerShell where it will not catch an exception even when the exception is explicitly mentioned in the catch command.</p>
  
  <p>In this case, I'm trying to determine if a ProcessID is still running, and if not then it will take some actions.</p>
  
  <p>The sample code block that I am struggling with is:</p>
  
  <pre><code>    try {
        Get-Process -Id 123123 -ErrorAction 'Stop'
      } 
      catch [Microsoft.PowerShell.Commands.ProcessCommandException] {
        "Caught by Exception Type: Process is missing"
      }
      catch {
      if ($_.Exception.getType().FullName -eq "Microsoft.PowerShell.Commands.ProcessCommandException") {
        "Caught by Catch All: Process is missing"
        }
      }
  </code></pre>
  
  <p>When this code block is executed the output is:</p>
  
  <pre><code>Caught by Catch All: Process is missing
  </code></pre>
  
  <p>You would expect the first catch condition to trigger as it names the exception being thrown correctly, but it doesn't trigger.</p>
  
  <p>To make things worse, when the second catch command runs (which catches anything) it queries the name of the exception type and checks if it is "Microsoft.PowerShell.Commands.ProcessCommandException" (which it is) and then takes appropriate steps.</p>
  
  <p>I know I can work around this, but I feel I'm missing a fundamental way about how PowerShell handles Exceptions.</p>
  
  <p>Can anyone shed light on this for me?</p>