Skip to main content

Let's Raise an Exception!

Now let's see Temporal in action!

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

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

from temporalio import activity

@activity.defn
async def withdraw_money(amount: float) -> bool:
raise Exception('Bank service temporarily unavailable')
print(f"Successfully withdrawn ${amount}")
return True

@activity.defn
async def deposit_money(amount: float) -> bool:
print(f"Successfully deposited ${amount}")
return True
6 / 9