Exception and Error in powershell -
try
block throws exception in catch
block resolve-error
method gets $error
null (zero elements in array), although $_.exception
gives me correct message. reason , how should resolve it?
function resolve-error($errorrecord=$error[0]) { $errorrecord | format-list * -force $errorrecord.invocationinfo | format-list * $exception = $errorrecord.exception ($i = 0; $exception; $i++, ($exception = $exception.innerexception)) { "$i" * 80 $exception | format-list * -force } } try { dsfhjbahdjfb } catch { write-host $_.exception if ($_.exception.response -ne $null) { $result = $_.exception.response.getresponsestream() $reader = new-object system.io.streamreader($result) $reader.basestream.position = 0 $reader.discardbuffereddata() $responsebody = $reader.readtoend(); write-host $responsebody } resolve-error throw "exception....." }
Comments
Post a Comment