title: PowerShell try/catch/finally
body: <p>I recently wrote a PowerShell script that works great - however, I'd like to now upgrade the script and add some error checking / handling - but I've been stumped at the first hurdle it seems. Why won't the following code work?</p>
  
  <pre><code>try {
    Remove-Item "C:\somenonexistentfolder\file.txt" -ErrorAction Stop
  }
  
  catch [System.Management.Automation.ItemNotFoundException] {
    "item not found"
  }
  
  catch {
    "any other undefined errors"
    $error[0]
  }
  
  finally {
    "Finished"
  }
  </code></pre>
  
  <p>The error is caught in the second catch block - you can see the output from <code>$error[0]</code>. Obviously I would like to catch it in the first block. What am I missing?</p>