Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
捕获Powershell中变量方法的终止错误_Powershell - Fatal编程技术网

捕获Powershell中变量方法的终止错误

捕获Powershell中变量方法的终止错误,powershell,Powershell,我试图捕获调用方法时引起的错误。在下面的try块中,Set Aclcmdlet支持ErrorAction并允许我捕获。方法.AddAccessRule不支持-ErrorAction,但如果用户不存在,则有时会失败。我怎样才能抓住这个错误 Try{ $acl.AddAccessRule($rule) Set-Acl $homeDirectory $acl -ErrorAction Stop -ErrorVariable errvar }Catch{ Log $NewUserL

我试图捕获调用方法时引起的错误。在下面的try块中,
Set Acl
cmdlet支持
ErrorAction
并允许我捕获。方法
.AddAccessRule
不支持-
ErrorAction
,但如果用户不存在,则有时会失败。我怎样才能抓住这个错误

 Try{
   $acl.AddAccessRule($rule)
   Set-Acl $homeDirectory $acl -ErrorAction Stop -ErrorVariable errvar
 }Catch{
   Log $NewUserLog $errvar
   $Response = [System.Windows.Forms.MessageBox]::Show("Unable to set security on user Folder. Please set NTFS permisions manually." + $ErrorText, "Error")
 }

catch块应捕获AddAccessRule引发的.NET异常。由于您尚未在catch块上指定筛选异常,因此它应该捕获所有“catchable”.NET异常。有一些异常没有捕获IIRC,比如StackOverflowException