【发布时间】:2016-03-18 16:45:10
【问题描述】:
我有一个try..catch 声明,但它没有引起注意,PS v4。
Function ReadFile ([string] $configfile) {
try {
[xml]$script:fileInfo = Get-Content $configFile
} catch {
Write-Host $_.Exception.Message
}
}
它永远不会捕获,但它在控制台中出错?以下是控制台错误:
获取内容:找不到路径“C:\test.xml”,因为它不存在。
在 C:\test.ps1:3 char:29
+ [xml]$script:fileInfo = 获取内容 $configFile
+ CategoryInfo : ObjectNotFound: (C:\test.xml:String) [Get-Content], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
【问题讨论】:
标签: powershell