Gre*_*SAT 0 powershell try-catch
我想从try块内退出:
function myfunc
{
try {
# Some things
if(condition) { 'I want to go to the end of the function' }
# Some other things
}
catch {
'Whoop!'
}
# Other statements here
return $whatever
}
Run Code Online (Sandbox Code Playgroud)
我用a测试过break,但这不起作用.如果任何调用代码在循环内,它会打破上层循环.
一个额外的脚本块try/catch和return它内部可能会这样做:
function myfunc($condition)
{
# Extra script block, use `return` to exit from it
.{
try {
'some things'
if($condition) { return }
'some other things'
}
catch {
'Whoop!'
}
}
'End of try/catch'
}
# It gets 'some other things' done
myfunc
# It skips 'some other things'
myfunc $true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12798 次 |
| 最近记录: |