Language reference · section 17

17. Errors

Feature: Errors

  Scenario: throw raises an error
    Given the code 'throw new RangeError("negative")'
    When the code runs
    Then the program raises a RangeError with the message "negative"

  Scenario: try with catch handles an error
    Given a try block with a catch err: block
    When the try block throws
    Then err holds the thrown value and the catch block runs

  Scenario: finally always runs
    Given a try block with a finally: block
    When a break or return leaves the block
    Then the finally block runs

  Scenario: try needs catch or finally
    Given a try block with neither catch nor finally
    Then the compiler reports an error "a try needs a catch or a finally block"

  Scenario: try and throw are not allowed in a @wasm function
    Given a @wasm function with a try block or a throw statement
    Then the compiler reports an error

  Scenario: Errors from workers and streams can be caught
    Given a try block around a call to a @worker function
    When the worker call fails
    Then the catch block runs