PowerShell的:创建一个自定义异常 [英] PowerShell: Creating a Custom Exception
本文介绍了PowerShell的:创建一个自定义异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的code:
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
}
我想替换#掷自定义异常
与code,这将导致捕捉
来火。我该怎么办呢?
I'd like to replace # Throw custom exception
with code that will cause the Catch
to fire. How can I do that?
推荐答案
不知道我真正得到你的问题,但似乎所有你想要做的是:
Not sure I really get your question, but it seems like all you want to do is to:
throw "message for the exception"
这篇关于PowerShell的:创建一个自定义异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文