Cheers,

TL;DR: If an exception handler is inside a specific action, and that action triggers said exception, the values of the local variables don't seem to be reset to their default values. Instead, they seem to hold the same values the action assigned them. Is it a good idea to use the value of those local variables in the exception? 

Explanation:

In this scenario, I have a lot of small actions that perform logic of some description (irrelevant) but they shouldn't be merged together. Every single one of those actions raises an exception if a set of conditions does not evaluate to true. I'll say that there is no reason to raise that exception, but this is somewhat old logic, and fiddling with it may have unintended consequences.

The actions use a database record that was created before they were called, but is not committed yet, because the action is not done yet. When any of them fails to calculate a specific part, it raises an exception. In the exception handler, it tries to read the file to write a detail log about that error.

Of course, raising the exception caused a Rollback in the Database, and the file is no longer there. The information the log requires is small. Can I assign that information to a local variable, before the exception is raised, and count on that value being there when the exception is caught?

(Note: According to my tests, this does NOT cause an infinite cycle. If an exception occurs inside an exception handler, it goes up on the handler hierarchy, it never calls the same exception handler twice, unless it raised high enough to reach the OnException handlers of the Screen Flow, specified in the UI Flow, where it will generate a 'special' error saying that there where 'too many redirects' ).

I do realize that there can be a real exception, and that value may be empty, but I will deal with that fact in the Exception Handler. But can I count on the value that I'll assign before raising that unnecessary exception is there, if no other exception interrupted the flow?

Also, can you post the reference from which you based your answer? I looked around before writing this post and found none.

Thank you for your attention



Solution

Yes, you can expect the local variables to keep their values and for those values to be accessible in the error handler flow, when an exception is thrown.

I often use that pattern to log additional business context about an exception.

Solution

João Pedro Abreu wrote:

Yes, you can expect the local variables to keep their values and for those values to be accessible in the error handler flow, when an exception is thrown.

I often use that pattern to log additional business context about an exception.

Hi João,

Thanks for the information. Do you know of any document or reference where that is written explicitly? 

Thanks again