.net - PowerShell:创建自定义异常

标签 .net powershell

这是我的代码:

Function Foo {
    If (1 -Eq 2) {
        # Do stuff
    }
    Else {
        # Throw custom exception
    }
}

Try {
    Foo

    Write-Host "Success"
}
Catch {
    $ErrorMessage = $_.Exception.InnerException.Message

    Write-Host "Failure"

    # Do stuff with the error message
}

我想用会导致# Throw custom exception触发的代码替换Catch。我怎样才能做到这一点?

最佳答案

不确定我是否真的收到您的问题,但是似乎您想要做的只是:

throw "message for the exception"

关于.net - PowerShell:创建自定义异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11703180/

相关文章:

powershell - 我们如何从失败的.msi安装中上传日志文件(使用WiX创建)

git - 在 PowerShell 中为 git 命令创建别名?

powershell - Copy-Item -Recurse 跳过创建一个子目录

powershell - PowerShell 中的 Add-PSSnapin 和 Import-Module 有什么区别?

powershell - Powershell if语句传递参数

c# - Request.UrlReferrer 为空?

C#:返回系统数据类型的聪明助手类

.net - Subsonic 如何处理连接?

.net - 更改 ToolTipText 显示持续时间

c# - 无法识别的 C# 语法