Senthil Arasu
Senthil Arasu

Reputation: 293

Exception Handling in Powershell

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.

Upvotes: 0

Views: 331

Answers (1)

Keith Hill
Keith Hill

Reputation: 202042

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" }

Upvotes: 2

Related Questions