Now inviting automation leaders: publish your playbook as a skill, under your own name. Publish yours →
Automation Skills
All skills/Uipath core/Xaml-error-handling
Reference · Uipath core

Xaml-error-handling

Part of Uipath core. Install the skill and your agent reads this page when it needs the depth.

Error Handling

TryCatch, Throw/Rethrow, exception types, RetryScope.

Contents

Try Catch

→ Use gen_try_catch() — generates correct XAML deterministically. Handles Catch block ordering, exception TypeArguments, and ActivityAction wrappers.

⚠️ TypeArguments must use xmlns prefix, never fully-qualified CLR names. Wrong: <Catch x:TypeArguments="System.Exception"> — XAML parser cannot resolve dotted CLR names. Right: <Catch x:TypeArguments="s:Exception"> — using the s: xmlns prefix. Same applies to ActivityAction, DelegateInArgument, Variable, and any element with x:TypeArguments. Common mappings: System.Exception → s:Exception, System.Data.DataTable → sd:DataTable, UiPath.Core.Activities.BusinessRuleException → ui:BusinessRuleException. Lint 99 catches this.

Throw / Rethrow

Throw expression syntax: [New ExceptionType("message")] — always VB.NET New keyword, always wrapped in [...] brackets. The Throw activity's Exception= attribute takes a VB.NET expression that creates the exception object.

→ Use gen_throw() — generates correct XAML deterministically.

Common mistakes to avoid:

Notes:

Exception Types — When to Use Which

BusinessRuleException (ui:BusinessRuleException)

ApplicationException (s:ApplicationException — System namespace)

System.Exception (s:Exception)

Catch block ordering rule: Most specific first, most general last.

<TryCatch.Catches>
  <!-- 1. Business rule issues (no retry) -->
  <Catch x:TypeArguments="ui:BusinessRuleException">...</Catch>
  <!-- 2. Application/technical issues (may retry) -->
  <Catch x:TypeArguments="s:ApplicationException">...</Catch>
  <!-- 3. Catch-all for anything unexpected -->
  <Catch x:TypeArguments="s:Exception">...</Catch>
</TryCatch.Catches>

REFramework SetTransactionStatus decision logic:

Exception caught
├─ Is BusinessRuleException?
│   ├─ Yes → Set status = Failed (BRE), log, move to next transaction
│   └─ No → Is retry limit reached?
│       ├─ Yes → Set status = Failed (Application), log, restart apps
│       └─ No → Increment retry counter, restart apps, retry same transaction

Common Specific Exception Types

Exception Namespace Typical Cause Action
ui:BusinessRuleException ui: Invalid data, business rule violation Skip transaction, notify
s:ApplicationException s: App crash, infra failure Retry, restart app
s:TimeoutException s: Operation exceeded time limit Retry with longer timeout
s:NullReferenceException s: Accessing null variable/object Fix logic, add null checks
s:ArgumentException s: Invalid argument to method Fix input data/logic
s:FormatException s: Parse failure (CInt, CDate on bad data) Validate input first
s:IO.IOException s: File locked, disk full, path not found Retry, check permissions
s:Net.WebException s: HTTP request failed, DNS error Retry with backoff

UiPath-specific (from uix: namespace):

Exception Property Access

' In Catch block, the exception variable (e.g., "exception") has:
exception.Message                    ' Error description
exception.GetType.Name               ' "BusinessRuleException", "ApplicationException"
exception.Source                     ' Assembly that threw
exception.StackTrace                 ' Full stack trace
exception.InnerException             ' Nested exception (can be Nothing)
exception.InnerException?.Message    ' Safe inner message access (C# only)

' VB.NET safe inner exception
If(exception.InnerException IsNot Nothing, exception.InnerException.Message, "")

' Check exception type in expressions (e.g., in If condition)
TypeOf exception Is BusinessRuleException
TypeOf exception Is ApplicationException

Error Handling Best Practices

1. Where to put TryCatch:

2. When to Rethrow vs handle:

3. Logging pattern:

' Always include: what failed + exception message + relevant context
"[ERROR] Failed to process invoice " + strInvoiceId + ": " + exception.Message
"[ERROR] API call failed for endpoint " + strEndpoint + " - Status: " + intStatusCode.ToString + " - " + exception.Message

4. Throw with inner exception (preserves stack trace): → Use gen_throw() — generates correct XAML deterministically.

The second parameter wraps the original exception as InnerException.

Retry Scope

→ Use gen_retryscope() — generates correct XAML deterministically.

Properties:

Empty condition variant — retry on any exception, no success check: → Use gen_retryscope() — generates correct XAML deterministically.

Use empty condition when you just want to retry on exception without validating a result.

Best practice — Navigation retry with NCheckState condition:

When retrying UI navigation, use NCheckState inside the Condition to verify the target page actually loaded. This is better than empty condition because it catches silent navigation failures (page didn't load but no exception thrown).

⛔ The element in NCheckState must be the FIRST element the next workflow will interact with (click, type into, get text, etc.) — NOT a generic page title or header. This guarantees the page is ready for the next action. Example: if the next step types into a search box, check for that search box; if the next step clicks an "Update" button, check for that button. → Use gen_ncheckstate() — generates correct XAML deterministically.

Use this pattern for: navigation retries, login verification (check for first dashboard element to interact with), page load confirmations. The NCheckState returns True if the element is found (success = stop retrying) or False if not found (keep retrying). Always target the first element the next workflow step will interact with — never a generic header or page title.

Common pattern — RetryScope wrapping TryCatch: → Use gen_retryscope() with gen_try_catch() nested inside — generates correct XAML deterministically.

⚠️ ALWAYS wrap API-interacting activities in RetryScope. Any activity that makes a network/API call can fail due to transient issues (timeouts, rate limits, DNS, connectivity). This includes:

Use empty condition (retry on any exception) for simple cases, or add a Condition with CheckTrue when you need to validate the response. Default: NumberOfRetries="3", RetryInterval omitted (Studio default). If you need custom intervals for external APIs with rate limits, set manually in Studio.

Exception: Activities already inside REFramework's Process.xaml — the framework's own retry mechanism (via SetTransactionStatus → Retry) handles transaction-level retries. But if Process.xaml makes multiple API calls, each individual call should still be wrapped in its own RetryScope to handle transient failures within a single transaction attempt.

Publish your skill

Copy this prompt into Claude Code, Codex or any agent. It walks you through your first skill in about 20 minutes, with you as the author.

Click to copy.