PowerShell try/catch/finally
问题 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? 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" } The error is caught in the second catch