try_

Creates a range expression out of a throwing functions

template try_(alias func)
try_
(
Args...
)
(
auto ref Args args
)

Examples

1 import std.typecons: Flag;
2 
3 void f0(Flag!"throws" throws) {
4     if (throws) {
5         throw new Exception("f0");
6     }
7 }
8 int f1(Flag!"throws" throws) {
9     if (throws) {
10         throw new Exception("f1");
11     }
12     return 0;
13 }
14 
15 auto f0_throws = try_!f0(Yes.throws);
16 auto f0_nothrows = try_!f0(No.throws);
17 
18 auto f1_throws = try_!f1(Yes.throws);
19 auto f1_nothrows = try_!f1(No.throws);
20 
21 auto g() {
22     try {
23         throw new Exception("hahah");
24     } catch (Exception ex) {
25         return ex;
26     }
27 }
28 
29 assert(!f0_throws.front.isExpected);
30 assert( f0_nothrows.front.isExpected);
31 assert(!f1_throws.front.isExpected);
32 assert( f1_nothrows.front.isExpected);

Meta

Since

- 0.0.1