How to catch errors correctly? server unreachable, fingerprint wrong, access denied, etc.
Hi,
I'm using this powershell code example:
library_powershell#module
I'm trying to differentiate between errors.
For example:
-host unreachable
-fingerprint wrong
-access denied
I replaced Exception with WinSCP.SessionRemoteException
but every of these 3 failures is a WinSCP.SessionRemoteException. -> didn't help
add failed handler:
Failed method didn't get called for every of these 3 failures -> didn't help
Session.output has the correct information but it's bad parseable text.
Sometimes it is the last line, sometimes not.
What do I do wrong?
I'm using this powershell code example:
library_powershell#module
I'm trying to differentiate between errors.
For example:
-host unreachable
-fingerprint wrong
-access denied
I replaced Exception with WinSCP.SessionRemoteException
catch [WinSCP.SessionRemoteException]
{
Write-Host "WinSCP.SessionRemoteException"
Write-Host $_.Exception.Message
exit 1
}add failed handler:
function Failed
{
param($e)
$e
}
$session.add_Failed( { Failed($_) } )Failed method didn't get called for every of these 3 failures -> didn't help
finally
{
# Disconnect, clean up
$session.output
$session.Dispose()
}Sometimes it is the last line, sometimes not.
What do I do wrong?