Need to force business exception in a flow - Best practice?

Hi everyone,

At some point of a process I’m using http request activity to download some files from a webservice.

If response status is 200 everything went ok, else something went wrong.

The problem: The activity does not throw an error if I for example get a 502 status witch means that the server was not responding so I basically want to:

  1. Capture the status of the response - Done and tested
  2. Force properly business exception in case status is not 200
  3. The process should continue, and set transaction status to failed by business

Another question is: The moment I force that business exception what the process will do?

I mean it will continue till the end and then setting up the status and getting next transaction item? Will stop the process at that point and set status and get another item? Or will stop the process and re-initialize everything to continue with the next item in the queue?

Thanks in advance,

You use the Throw activity to generate exceptions manually.

If you do not have the Throw inside a Try/Catch the job will immediately terminated as failed.

Typically you want to use Try/Catch to handle the exception. Put your steps in the Try block and when the exception is encountered it skips the rest of the steps and jumps to the appropriate Catch block where you perform your exception steps such as taking screenshots, sending emails, setting transaction status etc

1 Like

Well in order to force a business exception in the case where the HTTP request status is not 200, you can use the following steps:

  1. Surround the https activity within try block of a try catch activity
    Then add a new Throw activity in catch block
  2. Set the Exception property of the Throw activity to a New BusinessRuleException(“Failed to download file from web service”.)

This will ensure that the process fails with a business exception if the HTTP request status is not 200.

Whether the process will continue or stop after throwing the business exception depends on where the Throw activity is placed in the process.

If the Throw activity is placed at the end of the process, the process will stop and the transaction status will be set to failed.

If the Throw activity is placed in the middle of the process, the process will continue to the next activity after the Throw activity.

Hope this clarifies

Cheers @Pelayo_Celaya_Fernandez

1 Like

This is the logic now:

I have a few questions:

  1. The throw is in the Try block but the catch block is empty because how do I capture a non predefined excepction such as this one: New BusinessRuleException(“Failed to download file from web service”)
  2. After the try-catch as you can see there is more activities. My intended behaviour is that one the process throw and catch the business, the Process in reframework stops and then set the status transaction to failed with the business.

How can I continue with this?

You have mentioned a custom exception, BusinessRuleException, with a message like “Failed to download file from the web service.”

Here’s how you can capture and handle it:

  1. In your workflow, place the activity that may throw the BusinessRuleException within a Try Catch activity.
  2. In the Try block, include the activity that might throw the exception.
  3. In the Catch block, add a Catch activity for BusinessRuleException. To do this, click the “Add Exception” button within the Catch block, and select the BusinessRuleException type.
  4. Inside the Catch block for the BusinessRuleException, you can add activities to handle the exception. This might include logging the error, displaying a message to the user, or taking any other appropriate action.


1 Like

Here are the steps to implement this behavior:

1.In your workflow, within the Catch block for the BusinessRuleException, log the error message and then rethrow the exception: should have a mechanism to catch unhandled exceptions at a higher level, which can be done in the Process.xaml file. In the Process.xaml , you can add a Try Catch block to catch any unhandled exceptions

By configuring the Process.xaml this way, any unhandled exceptions, including the BusinessRuleException that is rethrown in your specific workflow, will be caught at this level. You can then log the error, set the transaction status to “Failed,” and the framework will handle it accordingly.

Note : - This approach ensures that when a BusinessRuleException is caught, it propagates to the framework, and the transaction status is set to “Failed,” stopping the process as intended.


1 Like

I’m getting half of what you say and I think is because my fault, I’ll try to give more details:

  1. I’m using reframework
  2. Since is it a simple process, the activity HTTP Request is placed in Process.xaml . The process that comes with the template. I know normaly this process is just a set of simple actions and it is used to invoke another handmade sub-processes using try-catch to do it. But in this case all the logic is directly implemented in the process since it is create a few folders and move the downloaded file from one to another.
  3. Basically what the process is doing is calling a webservice with some data retrieved from the queue. This should download a file in a specific folder and then move it to another one.
  4. The problem is that when Response Status is not 200, the activity does not throw per se an excepction. It just return the error code for example 404 and a message with the text for example Resource not found or whatever.
  5. When this happens the file is saved as it everything were ok but it didnt obviously.
  6. So I placed after that an if that checks if Response Status is 200 ( OK ).
  7. If it is 200 then I have not problem.
  8. If it is not 200 then I want to set up a business exception as you helped me.
  9. Now I use a throw in the Else block with: new Business…
  10. If I place this block of actions (http request + if ) in the Try Catch and Catch the new Business rule exception then the catch actions are performed. But the process will continue with more actions that I dont want to do.

The intended behaviour is that the throw implies that the process for that item finish in the catch block then gets out of Process.xaml and then set status transaction to business rule with the message I set up.

Within the “Catch” block where you catch the Business Rule Exception, you can add a “Throw” activity to rethrow the exception. This will stop the current execution and move to the next transaction item process the next queue item, effectively skipping any further actions within the current iteration.


1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.