HyperScript
Docs

← All of the Docs The basics

Handling errors

Guide and examples

Normally a line that cannot be done stops the trigger and reports the mistake. try: lets a script deal with it instead:

try:
    set {_data} to send get request to "https://hyperscript.monoforge.net/api/test"
    log "The website answered: %{_data}%"
on error:
    log "Could not reach the website: %{_error}%"

https://hyperscript.monoforge.net/api/test is a real address kept for trying requests out: it answers with the plain text Yup works.

  • If anything in the try: block fails, the rest of the block is skipped and the on error: block runs, with {_error} holding the message.
  • on error: is optional. Without it the failure is simply ignored and the script carries on.
  • fail "<text>" is a mistake of your own making: the trigger stops there as it does for any other, and a try: around it, also one in the code that called the function it is in, gets the text in {_error}. Outside a try: it ends the trigger and is written to the console.
  • Only mistakes made while running are caught. A line HyperScript cannot read still stops the whole file from loading.
  • A failure after a wait inside the block is not caught; put the try: after the wait.