Terminating a script in PowerShell

前端 未结 10 1871
走了就别回头了
走了就别回头了 2020-11-28 01:02

I\'ve been looking for a way to terminate a PowerShell (PS1) script when an unrecoverable error occurs within a function. For example:

function foo() {
    #         


        
10条回答
  •  攒了一身酷
    2020-11-28 01:19

    Throwing an exception will be good especially if you want to clarify the error reason:

    throw "Error Message"
    

    This will generate a terminating error.

提交回复
热议问题