[英]Creating custom CodeAccessSecurityAttribute leads to exception on compile
[英]PowerShell: Creating a Custom Exception
這是我的代碼:
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
}
我想用導致Catch
觸發的代碼替換# Throw custom exception
。 我怎樣才能做到這一點?
不確定我真的得到你的問題,但似乎你想要做的就是:
throw "message for the exception"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.