0

In a Scope Activity made in C#, I would like to prevent any exception to propagate to upper layer, a bit like the native try/catch activity.

Here is my code :

protected override async Task<Action<NativeActivityContext>> ExecuteAsync(NativeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs

            return (ctx) =>
            {

                // Schedule child activities
                if (Body != null)
                    ctx.ScheduleAction<IObjectContainer>(Body, _objectContainer, OnCompleted, OnFaulted);
               
            };
        }

Inside OnFaulted :

private void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            Console.WriteLine("OnFaulted");
            hasEncounteredException.Set(faultContext, true);
            exceptionMessage.Set(faultContext, propagatedException.Message);
            faultContext.CancelChildren();
            Cleanup();
        }

When I simulate an exception inside this scope activity, "OnFaulted" is displayed but then the RemoteException wrapping get my exception. How can I inside OnFaulted or inside ScheduleAction indicate to UiPath to not propagate the exception and to continue the next activity as if everything is fine ?

Thanks for your help

1 Answers1

0

By checking https://github.com/microsoft/referencesource/blob/master/System.Activities/System/Activities/Statements/TryCatch.cs

I found out that the line

faultContext.HandleFault();

handle the issue.

Here is my final code:

private void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
{
  Console.WriteLine("OnFaulted");
  ExceptionDetectee.Set(faultContext, true);
  Message.Set(faultContext, propagatedException.Message);
  faultContext.CancelChildren();
  Cleanup();
  faultContext.HandleFault();
}
Tyler2P
  • 2,324
  • 26
  • 22
  • 31