title: Handling Jenkins Groovy script exceptions
body: <p>I am executing a C# exe, CRS.exe, that I expect to return a non-zero value, such as -1.  I am using ps to get the value back, and have this within a stage: </p>
  
  <pre><code>  try{            
        pcode = (powershell(returnStdout: true, script: 'return Invoke-Expression -Command \" .\\perfmon\\CRS.exe hello \"'))''
        echo "Pcode =  ${pcode} "
        }
    catch (err) {echo err.message }
    echo "Pcode =  ${pcode} "
  </code></pre>
  
  <p>Based on this post, "Normally, a script which exits with a nonzero status code will cause the step to fail with an exception." --
  <a href="https://stackoverflow.com/questions/42428871/jenkins-pipeline-bubble-up-the-shell-exit-code-to-fail-the-stage">Jenkins pipeline bubble up the shell exit code to fail the stage</a>
  I want to handle this non-zero result, is the exception handler the only way?
  Results of above run:</p>
  
  <pre><code>    Running PowerShell script
  tester arg = hello    
  [Pipeline] echo
  script returned exit code -1
  [Pipeline] echo
  Pcode =  null 
  </code></pre>
  
  <p>Interestingly enough, a char return seems to be fine?  This returns without throwing an exception</p>
  
  <pre><code> icode = (powershell(returnStdout: true, script: 'return Invoke-Expression -Command \'.\\perfmon\\zipInstaller.ps1 -urlString ' + fileContents + "'"))
                  echo "icode =  ${icode} "
  
  Results in 
  [Pipeline] {
  [Pipeline] powershell
  [Chris] Running PowerShell script
  [Pipeline] echo
  icode =  -5
  </code></pre>
  
  <p>I would like to catch the return codes from the exe's and manage my groovy pipelines flow based on that.  Any insight would be greatly appreciated. </p>