Powershell error handling: do something if NO error occured
What about,
something
If ($?)
{
"No error"
}
Else
{
"Error"
}
This will work for non terminating errors too.
Another way:
$ErrorOccured = $false
try
{
$ErrorActionPreference = 'Stop'
...something...
}
catch
{
"Error occured"
$ErrorOccured=$true
}
if(!$ErrorOccured) {"No Error Occured"}
.
Check the automatic-variable $error
after you cleared it.
$error.clear()
try { something }
catch { "Error occured" }
if (!$error) { "No Error Occured" }