Dòng 2 trong kịch bản dưới đây tạo -Loại ngoại lệ nào nên được sử dụng trong Powershell để bắt lỗi phân tích cú pháp XML do các ký tự không hợp lệ?
"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"
ngoại lệ gì nên được chỉ định trên dòng 4 (của kịch bản) để bắt các lỗi nói trên?
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
}
Cám ơn tìm kiếm (và trả lời)
Adrian