locked
Exiting the script RRS feed

  • Question

  • Hello!

    This article says that "exit terminates the current execution session altogether. It also closes the console window and may or may not close ISE depending on what direction the wind is facing."

    I'm trying to end the script execution in the following situation:


    Try
    {
    Command1 -ErrorAction Stop
    }
    
    Catch
    {
    do smth
    exit
    }
    
    
    Command2
    ...
    
    Command-n

    ...but in case the error is raised in the Try section exit does NOT work in the Catch and all subsequent commands (Command2-CommandN) are executed.

    Should exit end the script execution when placed in the Catch section?

    Thank you in advance,

    Michael



    Wednesday, October 4, 2017 8:02 PM

Answers

  • Yes.  Assuming you have real code and not what you posted.

    \_(ツ)_/

    • Marked as answer by MF47 Thursday, October 5, 2017 12:14 PM
    Wednesday, October 4, 2017 8:41 PM