Skip to content

Commit 1715e15

Browse files
committed
Add throw/try/catch documentation
And bump build number
1 parent 6553e5f commit 1715e15

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docs/cpp2/functions.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,31 @@ outer: while i<M next i++ { // loop named "outer"
382382
```
383383

384384

385+
### <a id="catch"></a> `#!cpp throw`, `#!cpp try`, `#!cpp catch` — Exceptions
386+
387+
**`#!cpp throw`**, **`#!cpp try`** and **`#!cpp catch`** are like always in C++, except:
388+
389+
- `#!cpp throw(something)` requires parentheses around the thrown value
390+
- `#!cpp catch` uses Cpp2's usual [parameter syntax](#parameters), so you can write `#!cpp catch(obj: type)` to catch an exception of a specific type, and `#!cpp catch(_)` to catch any thrown exception
391+
392+
For example:
393+
394+
``` cpp title="Throw, try, catch"
395+
// This program will print "caught something else"
396+
main: () = {
397+
try {
398+
throw( "xyzzy" );
399+
}
400+
catch( i: int ) {
401+
std::cout << "caught int with value " << i;
402+
}
403+
catch( _ ) {
404+
std::cout << "caught something else";
405+
}
406+
}
407+
```
408+
409+
385410
## <a id="definite-last-use"></a> Move/forward from definite last use
386411

387412
In a function body, a **definite last use** of a local name is a single use of that name in a statement that is not in a loop, where no control flow path after that statement mentions the name again.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
cppfront compiler v0.8.2 Build B104:1552
2+
cppfront compiler v0.8.2 Build B110:1148
33
SPDX-License-Identifier Apache-2.0 WITH LLVM-exception
44
Copyright (c) 2022-2026 Herb Sutter

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"B104:1552"
1+
"B110:1148"

0 commit comments

Comments
 (0)