01-09-2013 01:34 PM
This is a sample code:
try {
$x = 0
$i = 1/$x
Write-Host $i
} catch [Exception] {
Write-Output "I am in Exception"
}
Write-Output "Completed"
In Powershell, the output I get is as expected.
In CPO, the customer is expecting the same, i.e for the code to go into exception handler. Currently, it is not and the actual exception is thrown.
CPO Version: 2.3.2
Thanks
01-09-2013 01:54 PM
Do you have a better example than a divide by zero? It does fail the script and returns a -1 code. If all you care about is failing or not failing then you can look for that output code.
If you have a more detailed use case and script I would suggest opening a TAC case and getting their support.
-shaun
01-09-2013 02:14 PM
Thanks Shaun.
It's not really about the script but just the behaviour of the powershell acitivity. The code doesn't go into a catch during an exception.
If this was the intended behaviour, then I assume it's to check the output code's and branch out accordingly and not having a huge powershell script in the activity.
The customer was expecting otherwise.
01-09-2013 03:57 PM
PO doesn't run the PowerShell script. We hand the script off to PowerShell, possibly on a remote environment. Just like when you run PowerShell from the command line or as a process, a failed script just returns an exit code, not the actual exception. This is what the activity sees, same as if you ran the script you paste into the activity as a file via the command line on the (possibly remote) Windows machine. The script itself needs to catch the script and do anything with it you want. In the PO process, your error handler can react to the error code returned by the Powershell script.
01-09-2013 04:01 PM
Justin Yancey came up with the following code snip to catch and output additional error information. Paste it in just below your Param section.
I haven't tried this personally, but it looked useful so I kept it around. Let us know if it helps.
trap {
"Error Category {0}`nError Type {1}`nID: {2}`nMessage: {3}" -f
$_.CategoryInfo.Category, $_.Exception.GetType().FullName,
$_.FullyQualifiedErrorID, $_.Exception.Message;
continue
}
$ErrorActionPreference = "Stop"
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide