powershell:如何在抛出异常时仅显示消息?
我需要在找不到目录时抛出一个异常,并抑制详细信息powershell:如何在抛出异常时仅显示消息?,powershell,throw,Powershell,Throw,我需要在找不到目录时抛出一个异常,并抑制详细信息 if( ! (Test-Path -Path $destDir) ) { throw "Directory $destDir not found!" } 在这种情况下,将显示消息和详细信息,在代码中抛出该消息 有没有办法只显示消息而不显示细节 (我测试了throw…2>$null,但这不起作用)在catch块中使用$\uuxception.Message。更多信息。您可以使用写入错误和退出/中断@Paul write error也会
if( ! (Test-Path -Path $destDir) )
{
throw "Directory $destDir not found!"
}
在这种情况下,将显示消息和详细信息,在代码中抛出该消息
有没有办法只显示消息而不显示细节
(我测试了throw…2>$null
,但这不起作用)在catch块中使用$\uuxception.Message
。更多信息。您可以使用写入错误
和退出
/中断
@Paul write error也会显示详细信息。我的解决方案是使用写主机“目录丢失”-ForegroundColor Red
。谢谢我在你的链接中找到了我需要的解决方案:写主机“目录丢失”-ForegroundColor红色
,然后退出
。我不需要抛出异常。典型的新手不知道概念问题。谢谢