What exception type should be used in Powershell to catch a XML parse error due to invalid characters?

自闭症网瘾萝莉.ら 提交于 2019-12-01 17:14:56

Here is a way to discover yourself the full type name of an Exception, the result here gives System.Management.Automation.ArgumentTransformationMetadataException as given by @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
}

System.Management.Automation.ArgumentTransformationMetadataException

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!