Try
Runs steps that might fail, like an API call, and catches the failure instead of stopping. In catch, `error.message` says what went wrong.
Category: Logic
#When to use it
Use it around steps marked Can fail, like Call API or Face ID / Touch ID, to handle a failure your way instead of the run stopping with an error.
#Example
Loading the weather:
- Do: Call API with Url:
https://api.example.com/forecastand Into: forecast - Catch: Show Message with Text: ⚡︎ → From this action → error.message, Style: Error
#Good to know
- When a step in Do fails, the rest of Do is skipped, Catch runs, and the steps after the Try carry on.
- In Catch,
error.messagesays what went wrong. After a server answered a Call API with an error,error.statusis its status number anderror.bodyits answer. - An empty Catch quietly ignores the failure.
- Stop inside Do still ends the whole run. So does closing the camera or a picker without choosing: that isn't a failure, so Try doesn't catch it.
- Preview's debugger notes "Try caught it" when it does.
#Add it
Select a view, open the Inspector's Actions tab, pick when it runs, tap Add action and choose Try (under Logic). Tap the step to open its settings.
#Settings
| Setting | What it does | Kind | Default |
|---|---|---|---|
| Do | The steps to try. | Steps | Required |
| Catch | Runs if one of them fails. | Steps | Optional |