Powershell Error Handling


JAMS monitors Powershell script execution for more than just an exit code. We trap exceptions thrown by Powershell and look for error objects in the Powershell error pipeline.  This provides better error handling possibilities than a simple exit code.  Within Powershell, your script can do:

Throw “Your error message here”

And the JAMS job will fail and show a final status of “Your error message here”.

We check the return code from the process but, a value of 0 means that our PowerShell host worked properly (even though the PowerShell script may have failed).  A return code other than 0 would indicate a problem with our host.

By setting the job's notify options, you can receive notification of non-terminating errors within Powershell scripts that might have completed with an exit code 0. 


Have more questions? Submit a request


  • Avatar
    Charlie Demsky

    Is there a way to end the job with a Warning severity instead of failing it when using the Throw command?

  • Avatar
    Louis Diaz

    Hello Charlie,

    The Throw command will always terminate with an error severity.

    However, a possible workaround would be to use an exit warning code within the PowerShell source code itself. In this example the exit number is set to 911.


    Then we can add this exit code value to exit as a warning:
    Right-click job --> Properties --> Select Properties tab --> Source Options --> Specific Exit Code Values --> Warning: (Enter value here) for example 911.