Powershell error handling: do something if NO error occured

powershell, try-catch

Solution

Check the automatic-variable `$error` after you cleared it.

$error.clear()
try { something }
catch { "Error occured" }
if (!$error) { "No Error Occured" }

Problem

I've been searching around for this but can't seem to find it. I'm having a script with a try {} catch {} statement. I'd like to add an action if NO error occured. Eg ``` try { something } catch { "Error occured" } if (!error) { "No Error Occured" } ``` How can I test if no error occured in the statement? Thanks in advance Walter

Original source