पंक्ति 2 नीचे लिपि में उत्पन्न करता है -अमान्य वर्णों के कारण XML पार्स त्रुटि को पकड़ने के लिए पावरहेल में किस अपवाद प्रकार का उपयोग किया जाना चाहिए?
"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"
क्या अपवाद ऊपर उल्लिखित त्रुटि को पकड़ने के लिए (स्क्रिप्ट के) लाइन 4 पर निर्दिष्ट किया जाना चाहिए? देख (और जवाब देने) के लिए
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
}
धन्यवाद
एड्रियन