PadCodedocs

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/forecast and Into: forecast
  • Catch: Show Message with Text: ⚡︎ → From this action → error.message, Style: Error
A Try open, with a Call API and Set Value steps inside Do.

#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.message says what went wrong. After a server answered a Call API with an error, error.status is its status number and error.body its 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

SettingWhat it doesKindDefault
DoThe steps to try.StepsRequired
CatchRuns if one of them fails.StepsOptional

#See also