How to throw Exceptions within Custom Activity

I have created a Custom Activity using the latest information available from UiPath, but I am encountering an issue where it appears Studio automatically supresses any exception I try to throw.

In this example here, I have a GET request I am sending to an API endpoint (the API is currently down for maintenance) so it is not returning a success status code. This method I am calling throws an exception if the status code is not successful:

However in Studio there is not an exception thrown and it simply continues on to the next activity:
image

How can I throw this exception to the end user in Studio?

@phaynes,

Use Try Catch in your activity code and in catch section use rethrow to throw the exception out.

Thanks,
Ashok :slight_smile:

It’s not activities, it’s code. And you don’t need to use a Try then Rethrow. You just Throw.

@phaynes Don’t do any error handling in your custom activity and the error will bubble up to the activity container.

Throw New System.Exception("exception message")

It can be any type of exception you want, of course, like BusinessRuleException.

@ashokkarale @postwick

From what I can tell, the “ExecuteAsync” method is the “main” method of the activities, or the one that is called upon instantiation of the activity in Studio. If I throw an error in this method, I can validate what you said above:

Shows in Studio:
image

The issue is that I have my logic segmented in separate protected methods within the Activity class. So none of the errors I throw are in this top-level method. For example, I put this same exception one method deeper in the “ExecuteWithTimeout” method:

And yet in Studio, this error is suppressed and Studio continues past it as if nothing happened (which is what causes the log message exception):
image

Is there a way I can propagate the exception in the top-most level and manually throw it later in the code, so that way it throws at this top level?

Sounds like this is more of a vb.net question than a UiPath question. And that’s not something I know enough about to help you.

For any users looking for answers I figured it out.

The task object contains an “Exception” property:

If there isn’t an exception it will be null, meaning you can do a check like you see above on whether the completed task was completed due to an exception. If it is, you can rethrow the same exception in this top level and it will appear in Studio:
image

Hope this helps!

1 Like

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