'Proper' method to break out of Try/Catch in Deploy-Application.ps1

//'Proper' method to break out of Try/Catch in Deploy-Application.ps1
'Proper' method to break out of Try/Catch in Deploy-Application.ps1 2017-02-06T18:35:33+00:00

The Toolkit Forums General 'Proper' method to break out of Try/Catch in Deploy-Application.ps1

  • Author
    Posts
  • Julius
    Participant
    Post count: 13
    #1916 |

    What’s the appropriate method for breaking out of the main Try/Catch in Deploy-Application.ps1 to cause a failed installation/uninstallation?
    If I ‘Throw’, it’ll display a nasty window to the user which is not what we want.
    The ‘workaround’ for now is to simply Execute-Process that will fail.

    Is there a better way?

  • Matt
    Participant
    Post count: 11

    If the end goal is to throw a failure, you use exit-script -exitcode 2 <– or anything not a success. Put that wherever you want it to stop and you’re golden. If you’re looking to passthru exit codes from process, go see my last post here.

  • Julius
    Participant
    Post count: 13

    Shoot – I was too focused on breaking out of try/catch properly that I hadn’t considered simply exiting via the built-in function!
    I don’t require anything in particular returned as the script is checking to validate a prerequisite, and if it’s not met, the script terminates. So sure, exitcode 1, 2 etc is fine.
    Thanks again.

You must be logged in to reply to this topic.