David Klempfner
David Klempfner

Reputation: 9870

Point of Write-Error in Catch block

If you are only catching Exceptions to display the error in a more user friendly way, would there be any point in using Write-Error over Write-Host? Write-Error would just show the Exception the same way it would if you didn't catch it right?

Upvotes: 1

Views: 172

Answers (1)

mjolinor
mjolinor

Reputation: 68273

One reason you'd want to use Write-Error over Write-Host is that it will be written to the Powershell Error stream, and can be redirected if you wanted to do that later (e.g. running the script as a scheduled task, and want to capture that output to a log file).

Upvotes: 1

Related Questions