Re: How to catch errors correctly? server unreachable, fingerprint wrong, access denied, etc.
OK, I'll consider that.
Indeed the mere$e
expression does not yield any output.
Anyway, it's the same information as you get from the exception, so it won't help.
The best you can do is to parse Exception message (not log).
Session.Failed
is called all these scenarios.
$e
expression does not yield any output. I do not know why, I do not know PowerShell good enough. But Write-Host $e
does.
catch [WinSCP.SessionRemoteException]
{
Write-Host "WinSCP.SessionRemoteException"
Write-Host $_.Exception.Message
exit 1
}
function Failed
{
param($e)
$e
}
$session.add_Failed( { Failed($_) } )
finally
{
# Disconnect, clean up
$session.output
$session.Dispose()
}