You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Errors in activity functions and sub-orchestrations
19
19
20
-
Any exception that is thrown in an activity function is marshaled back to the orchestrator function and thrown as a `FunctionFailedException`. You can write error handling and compensation code that suits your needs in the orchestrator function.
20
+
In Durable Functions, unhandled exceptions thrown within activity functions or sub-orchestrations are marshaled back to the orchestrator function using standardized exception types.
21
21
22
-
For example, consider the following orchestrator function that transfers funds from one account to another:
22
+
For example, consider the following orchestrator function that performs a fund transfer between two accounts:
23
23
24
24
# [C# (InProc)](#tab/csharp-inproc)
25
+
In Durable Functions C# in-process, unhandled exceptions are thrown as [FunctionFailedException](/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.functionfailedexception).
26
+
27
+
The exception message typically identifies which activity functions or sub-orchestrations caused the failure. To access more detailed error information, inspect the `InnerException` property.
25
28
26
29
```csharp
27
30
[FunctionName("TransferFunds")]
@@ -45,7 +48,7 @@ public static async Task Run([OrchestrationTrigger] IDurableOrchestrationContext
45
48
Amount=transferDetails.Amount
46
49
});
47
50
}
48
-
catch (Exception)
51
+
catch (FunctionFailedException)
49
52
{
50
53
// Refund the source account.
51
54
// Another try/catch could be used here based on the needs of the application.
@@ -64,6 +67,10 @@ public static async Task Run([OrchestrationTrigger] IDurableOrchestrationContext
64
67
65
68
# [C# (Isolated)](#tab/csharp-isolated)
66
69
70
+
In Durable Functions C# Isolated, unhandled exceptions are surfaced as [TaskFailedException](/dotnet/api/microsoft.durabletask.taskfailedexception).
71
+
72
+
The exception message typically identifies which activity functions or sub-orchestrations caused the failure. To access more detailed error information, inspect the [FailureDetails](/dotnet/api/microsoft.durabletask.taskfailuredetails) property.
73
+
67
74
```csharp
68
75
[FunctionName("TransferFunds")]
69
76
publicstaticasyncTaskRun(
@@ -85,7 +92,7 @@ public static async Task Run(
85
92
Amount=transferDetails.Amount
86
93
});
87
94
}
88
-
catch (Exception)
95
+
catch (TaskFailedException)
89
96
{
90
97
// Refund the source account.
91
98
// Another try/catch could be used here based on the needs of the application.
@@ -99,6 +106,10 @@ public static async Task Run(
99
106
}
100
107
```
101
108
109
+
> [!NOTE]
110
+
> - The exception message typically identifies which activity functions or sub-orchestrations caused the failure. To access more detailed error information, inspect the [`FailureDetails`](/dotnet/api/microsoft.durabletask.taskfailuredetails) property.
111
+
> - By default, `FailureDetails` includes the **error type**, **error message**, **stack trace**, and any **nested inner exceptions** (each represented as a recursive `FailureDetails` object). If you want to include additional exception properties in the failure output, see [Include Custom Exception Properties for FailureDetails (.NET Isolated)](#include-custom-exception-properties-for-failuredetails-net-isolated).
112
+
102
113
# [JavaScript (PM3)](#tab/javascript-v3)
103
114
104
115
```javascript
@@ -185,7 +196,7 @@ main = df.Orchestrator.create(orchestrator_function)
185
196
```
186
197
# [PowerShell](#tab/powershell)
187
198
188
-
By default, cmdlets in PowerShell do not raise exceptions that can be caught using try/catch blocks. You have two options for changing this behavior:
199
+
By default, cmdlets in PowerShell don't raise exceptions that can be caught using try/catch blocks. You have two options for changing this behavior:
189
200
190
201
1. Use the `-ErrorAction Stop` flag when invoking cmdlets, such as `Invoke-DurableActivity`.
191
202
2. Set the [`$ErrorActionPreference`](/powershell/module/microsoft.powershell.core/about/about_preference_variables#erroractionpreference) preference variable to `"Stop"` in the orchestrator function before invoking cmdlets.
@@ -235,6 +246,122 @@ public void transferFunds(
235
246
236
247
If the first **CreditAccount** function call fails, the orchestrator function compensates by crediting the funds back to the source account.
237
248
249
+
## Errors in entity functions
250
+
Exception handling behavior for entity functions differs based on the Durable Functions hosting model:
251
+
252
+
# [C# (InProc)](#tab/csharp-inproc)
253
+
254
+
In Durable Functions using C# in-process, original exception types thrown by entity functions are directly returned to the orchestrator.
thrownewInvalidOperationException("this is an entity exception");
280
+
case"get":
281
+
ctx.Return(ctx.GetState<int>());
282
+
break;
283
+
}
284
+
}
285
+
```
286
+
287
+
# [C# (Isolated)](#tab/csharp-isolated)
288
+
289
+
In Durable Functions C# Isolated, exceptions are surfaced to the orchestrator as an `EntityOperationFailedException`. To access the original exception details, inspect its `FailureDetails` property.
Entity functions aren't currently not supported in PowerShell.
358
+
359
+
# [Java](#tab/java)
360
+
361
+
Entity functions aren't currently not supported in Java.
362
+
363
+
---
364
+
238
365
## Automatic retry on failure
239
366
240
367
When you call activity functions or sub-orchestration functions, you can specify an automatic retry policy. The following example attempts to call a function up to three times and waits 5 seconds between each retry:
@@ -365,7 +492,7 @@ The activity function call in the previous example takes a parameter for configu
365
492
366
493
## Custom retry handlers
367
494
368
-
When using the .NET or Java, you also have the option to implement retry handlers in code. This is useful when declarative retry policies are not expressive enough. For languages that don't support custom retry handlers, you still have the option of implementing retry policies using loops, exception handling, and timers for injecting delays between retries.
495
+
When using the .NET or Java, you also have the option to implement retry handlers in code. This is useful when declarative retry policies aren't expressive enough. For languages that don't support custom retry handlers, you still have the option of implementing retry policies using loops, exception handling, and timers for injecting delays between retries.
369
496
370
497
# [C# (InProc)](#tab/csharp-inproc)
371
498
@@ -636,12 +763,91 @@ public boolean timerOrchestrator(
636
763
---
637
764
638
765
> [!NOTE]
639
-
> This mechanism does not actually terminate in-progress activity function execution. Rather, it simply allows the orchestrator function to ignore the result and move on. For more information, see the [Timers](durable-functions-timers.md#usage-for-timeout) documentation.
766
+
> This mechanism doesn't actually terminate in-progress activity function execution. Rather, it simply allows the orchestrator function to ignore the result and move on. For more information, see the [Timers](durable-functions-timers.md#usage-for-timeout) documentation.
640
767
641
768
## Unhandled exceptions
642
769
643
770
If an orchestrator function fails with an unhandled exception, the details of the exception are logged and the instance completes with a `Failed` status.
644
771
772
+
## Include Custom Exception Properties for FailureDetails (.NET Isolated)
773
+
774
+
When running Durable Task workflows in the .NET Isolated model, task failures are automatically serialized into a FailureDetails object. By default, this object includes standard fields such as:
775
+
- ErrorType — the exception type name
776
+
- Message — the exception message
777
+
- StackTrace — the serialized stack trace
778
+
- InnerFailure – a nested FailureDetails object for recursive inner exceptions
779
+
780
+
Starting with Microsoft.Azure.Functions.Worker.Extensions.DurableTask [v1.9.0](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.DurableTask/1.9.0), You can extend this behavior by implementing an IExceptionPropertiesProvider (defined in the Microsoft.DurableTask.Worker starting from [v1.16.1](https://www.nuget.org/packages/Microsoft.DurableTask.Worker/1.16.1)package). This provider defines which exception types and which of their properties should be included in the FailureDetails.Properties dictionary.
781
+
782
+
> [!NOTE]
783
+
> - This feature is available in **.NET Isolated** only. Support for Java will be added in a future release.
784
+
> - Make sure you're using **Microsoft.Azure.Functions.Worker.Extensions.DurableTask v1.9.0** or later.
785
+
> - Make sure you're using **Microsoft.DurableTask.Worker v1.16.1** or later.
786
+
787
+
### Implement an Exception Properties Provider
788
+
Implement a custom IExceptionPropertiesProvider to extract and return selected properties for the exceptions you care about. The returned dictionary will be serialized into the Properties field of FailureDetails when a matching exception type is thrown.
0 commit comments