Skip to main content

Let's Throw an Exception!

Now let's see Temporal in action!

We’ll now look at how Temporal retries your code. We’ll intentionally throw an exception in the withdrawMoney Activity code.

In our case, this is just an exception we are intentionally throwing, but this could just as easily be an internal service that isn't responding, a network outage, an application crashing, or more.

using Temporalio.Activities;

public class Activities
{
[Activity]
public Task<bool> withdrawMoney(double amount)
{
throw new Exception("Bank service temporarily unavailable");
Console.WriteLine($"Successfully withdrawn $${amount}");
return Task.FromResult(true);
}

[Activity]
public Task<bool> depositMoney(double amount)
{
Console.WriteLine($"Successfully deposited $${amount}");
return Task.FromResult(true);
}
}
6 / 9