From dfbd984ee77ef015fd9171ccfbfacc4bfbb3888c Mon Sep 17 00:00:00 2001 From: wingbot <109207340+monadabot@users.noreply.github.com> Date: Wed, 30 Aug 2023 02:34:41 +0300 Subject: [PATCH] feat(docs): update docs (#583) feat(docs): update docs Updates the Wing docs. See details in [workflow run]. [Workflow Run]: https://github.com/winglang/docsite/actions/runs/6018610819 ------ *Automatically created via the "update-docs" workflow* --- .../version-latest/03-language-reference.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/versioned_docs/version-latest/03-language-reference.md b/versioned_docs/version-latest/03-language-reference.md index 69fc22a73..6f9445064 100644 --- a/versioned_docs/version-latest/03-language-reference.md +++ b/versioned_docs/version-latest/03-language-reference.md @@ -516,12 +516,10 @@ log("UTC: ${t1.utc.toIso())}"); // output: 2023-02-09T06:21:03.000Z | Name | Extra information | | -------- | -------------------------------------------------------- | | `log` | logs str | -| `throw` | creates and throws an instance of an exception | | `assert` | checks a condition and _throws_ if evaluated to false | > ```TS > log("Hello ${name}"); -> throw("a recoverable error occurred"); > assert(x > 0); > ``` @@ -1173,7 +1171,7 @@ The loop invariant in for loops is implicitly re-assignable (`var`). ### 2.7 while -**while** statement is used to execute a block of code while a condition is true. +The **while** statement evaluates a condition, and if it is true, a set of statements is repeated until the condition is false. > ```TS > // Wing program: @@ -1186,6 +1184,20 @@ The loop invariant in for loops is implicitly re-assignable (`var`). --- +### 2.8 throw + +The **throw** statement raises a user-defined exception, which must be a string expression. +Execution of the current function will stop (the statements after throw won't be executed), and control will be passed to the first catch block in the call stack. +If no catch block exists among caller functions, the program will terminate. +(An uncaught exception in preflight causes a compilation error, while an uncaught exception in inflight causes a runtime error.) + +> ```TS +> // Wing program: +> throw "Username must be at least 3 characters long."; +> ``` + +[`▲ top`][top] + ## 3. Declarations ### 3.1 Structs