powershell 2.0 try catch how to access the exception

前端 未结 1 1319
迷失自我
迷失自我 2020-12-04 13:42

This is the try catch in PowerShell 2.0

$urls = \"http://www.google.com\", \"http://none.greenjum         


        
相关标签:
1条回答
  • 2020-12-04 14:14

    Try something like this:

    try {
        $w = New-Object net.WebClient
        $d = $w.downloadString('http://foo')
    }
    catch [Net.WebException] {
        Write-Host $_.Exception.ToString()
    }
    

    The exception is in the $_ variable. You might explore $_ like this:

    try {
        $w = New-Object net.WebClient
        $d = $w.downloadString('http://foo')
    }
    catch [Net.WebException] {
        $_ | fl * -Force
    }
    

    I think it will give you all the info you need.

    My rule: if there is some data that is not displayed, try to use -force.

    0 讨论(0)
提交回复
热议问题