0
votes

Am creating a powershell script for Biztalk deployment. I wrote a normal try catch block to handle the exceptions during the deployment. My Code was able to catch the Exceptions like

# File Not Found
# Syntax Errors

But exception like Dependency applications needs to be installed before installing - was not getting caught. But when i check the Powershell console i can see..
CommandExecuted with 1 Error.

Please Suggest how to handle these exceptions.

1
catch will intercept "terminating errors" only. Try setting $ErrorActionPreference = "stop" on top of your script - Loïc MICHEL
I have added that code on top of the script. Only then my other exceptions are getting caught. - Senthil Arasu
could you share your script ? - Loïc MICHEL

1 Answers

2
votes

In addition to non-terminating errors, you should be aware that PowerShell try/catch does not "catch" the fact that an executable returned an error exit code. You can make it generate an exception like so:

some.exe someargs
if ($LastExitCode -ne 0) { throw "some.exe failed with exit code $LastExitCode" }