PowerShell 2.0 以降は、try-catch が使用できる。
try
{
$x = 1 / 0
}
catch [Exception]
{
$retMessage = $_.Exception.Message
#Write-Host $retMessage
# 0 で除算しようとしました。
}
finally
{
}