6

Linia 2 poniższy skrypt generuje -Jaki typ wyjątku powinien zostać użyty w pakiecie Powershell, aby wykryć błąd analizy XML spowodowany nieprawidłowymi znakami?

"Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "'→', hexadecimal value 0x1A, is an invalid character. Line 39, position 23."

At line:1 char:8 + [xml]$x <<<< = Get-Content 4517.xml + CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException + FullyQualifiedErrorId : RuntimeException"

Co wyjątek powinien być określony na linii 4 (skryptu), aby złapać wspomniany błąd?

try { 
    [xml]$xml = Get-Content $file # line 2 
} 
catch [?] {      # line 4 
    echo "XML parse error!" 
    # handle the parse error differently 
} 
catch { 
    echo $error 
    # some general error 
} 

Dzięki za szuka (i odbieranie)

Adrian

Odpowiedz

5

Oto sposób, aby odkryć siebie pełną nazwę type wyjątku, Wynik tutaj daje System.Management.Automation.ArgumentTransformationMetadataException jak podaje @Adrian Wright.

Clear-Host 
try { 
    [xml]$xml = Get-Content "c:\Temp\1.cs" # line 2 
} 
catch { 
    # Discovering the full type name of an exception 
    Write-Host $_.Exception.gettype().fullName 
    Write-Host $_.Exception.message 
} 
3

System.Management.Automation.ArgumentTransformationMetadataException

Powiązane problemy