mirror of
https://github.com/dlang/dmd.git
synced 2025-04-29 06:30:10 +03:00
Changelog entry for throw expressions
This commit is contained in:
parent
22d6311c6f
commit
b425f05e8c
1 changed files with 32 additions and 0 deletions
32
changelog/throw_expression.dd
Normal file
32
changelog/throw_expression.dd
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
Throw expression as proposed by DIP 1034 have been implemented
|
||||||
|
|
||||||
|
Prior to this release, `throw` was considered as a statement and hence was not
|
||||||
|
allowed to appear inside of other expressions. This was cumbersome e.g. when
|
||||||
|
wanting to throw an expression from a lambda:
|
||||||
|
|
||||||
|
---
|
||||||
|
SumType!(int, string) result;
|
||||||
|
|
||||||
|
result.match!(
|
||||||
|
(int num) => writeln("Found ", num),
|
||||||
|
// (string err) => throw new Exception(err) // expression expected
|
||||||
|
(string err) { throw new Exception(err); } // ok, introduces an explicit body
|
||||||
|
|
||||||
|
);
|
||||||
|
---
|
||||||
|
|
||||||
|
`throw` is now treated as an expression as specified by DIP 1034 [1], causing
|
||||||
|
it to become more flexible and easier to use.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
SumType!(int, string) result;
|
||||||
|
|
||||||
|
result.match!(
|
||||||
|
(int num) => writeln("Found ", num),
|
||||||
|
(string err) => throw new Exception(err) // works
|
||||||
|
|
||||||
|
);
|
||||||
|
---
|
||||||
|
|
||||||
|
[1] https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1034.md
|
Loading…
Add table
Add a link
Reference in a new issue