Changelog entry for throw expressions

This commit is contained in:
MoonlightSentinel 2021-10-12 19:08:00 +02:00
parent 22d6311c6f
commit b425f05e8c
No known key found for this signature in database
GPG key ID: 1A1A60AECDC956AB

View 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