Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

The JS7 - Try / Catch Instruction is  can be used for the error handling in a workflow. If any job runs in the try block and failed due to any reason the catch block will execute otherwise it will skip the catch block. If the catch block will also fail then the Order will be considered as failed. The folder 04_ErrorHandling contains the example for the try-catch. The four workflows are available with the different use cases for the try-catch:The jsTryCatch workflow is used for error handling when the execution of the job in the try block will fail the catch will execute and try to complete the Order successfully. If the catch will execute and fail then the Order is considered as failed. In the example, if the try block generates an odd no then the catch block will execute and try to create an even number to complete the workflow. If the catch block fails to create an even number, the Order will fail and end the execution.within a Try Instruction block fails then the jobs available from the Catch Instruction block will be executed. If no error occurs in the Try Instruction block then the jobs in the Catch Instruction block are skipped. If a job in a Catch Instruction block also fails then the order will be considered being failed. Nested try/catch blocks can be used for more complex error handling.

Workflow

The jsTryCatch workflow demonstrates the use of Try/Catch Instruction blocks for error handling. In this example the job job2_b in the Try Instruction block generates a random number. If an even value is generated then no error and no error handling with the Catch Instruction block occurs. If an odd value is generated then the jobs in the Catch Instruction block will be executed. You might have to run this workflow a number of times to find different behavior with errors being caused by random numbers.

To execute the workflow in the folder 04_ErrorHandling please follow the below steps:

  1. Click on the folder 04_ErrorHandling and expand the jsTryCatch workflow.



  2. To add the Order in an order to the workflow . Click on click the action menu of the workflow and click on use Add Order button from the drop-down menu.



  3. On clicking the When clicking Add Order. A  a popup window will appear. 
  4. You can add the an Order ID or leave the Order Id ID value blank empty, it will take the then use a default Order Id to process the OrderID. Click on the Submit button to add the Order.



  5. To check the status of the Order order click on the Workflow name with this new Order history panel will appear. name of the workflow. This will make the Order History panel appear.



  6. From the Order history History panel , you can see verify that the Order order is  successful and finished or failed - depending on random numbers generating errors. Click on the Order ID to open the detail logs of executionsee log output created by jobs executed for this order.



  7. A log view window will open and the Order order log will be displayed. The Order This log contains log output to stdout/stderr from all jobs executed by the Orderorder. 
  8. You can download the log file by clicking the Download button from the upper right corner of the log view window. Also, you can expand and collapse the individual job output using the arrow button chevron icons from the left upper corner of the log view window.