@@ -5,6 +5,39 @@ Most of API Required DIP1008.
5
5
+/
6
6
module mir.exception ;
7
7
8
+ version (D_Exceptions):
9
+
10
+ // /
11
+ auto ref enforce (string fmt, string file = __FILE__ , int line = __LINE__ , Expr)(scope auto return ref Expr arg) @trusted
12
+ {
13
+ import mir.functional: forward;
14
+ import mir.utility: _expect;
15
+ static if (__traits(compiles, arg ! is null ))
16
+ {
17
+ if (_expect(arg ! is null , true ))
18
+ return forward! arg[0 ];
19
+ }
20
+ else
21
+ {
22
+ if (_expect(cast (bool )arg, true ))
23
+ return forward! arg[0 ];
24
+ }
25
+ static immutable exception = new Exception (fmt, file, line);
26
+ throw exception;
27
+ }
28
+
29
+ // /
30
+ @safe pure nothrow @nogc
31
+ version (mir_test) unittest
32
+ {
33
+ import mir.exception;
34
+ try enforce! " Msg" (false );
35
+ catch (Exception e) assert (e.msg == " Msg" );
36
+ }
37
+
38
+ static if (__traits(compiles, (()@nogc {throw new Exception (" " );})()))
39
+ {
40
+
8
41
/+ +
9
42
+/
10
43
class MirException : Exception
@@ -123,33 +156,6 @@ version (mir_test) unittest
123
156
// catch(Exception e) assert(e.msg == "Msg");
124
157
// }
125
158
126
- // /
127
- auto ref enforce (string fmt, string file = __FILE__ , int line = __LINE__ , Expr)(scope auto return ref Expr arg) @trusted
128
- {
129
- import mir.functional: forward;
130
- import mir.utility: _expect;
131
- static if (__traits(compiles, arg ! is null ))
132
- {
133
- if (_expect(arg ! is null , true ))
134
- return forward! arg[0 ];
135
- }
136
- else
137
- {
138
- if (_expect(cast (bool )arg, true ))
139
- return forward! arg[0 ];
140
- }
141
- static immutable exception = new Exception (fmt, file, line);
142
- throw exception;
143
- }
144
-
145
- // /
146
- @safe pure nothrow @nogc
147
- version (mir_test) unittest
148
- {
149
- import mir.exception;
150
- try enforce! " Msg" (false );
151
- catch (Exception e) assert (e.msg == " Msg" );
152
- }
153
159
154
160
/+ +
155
161
+/
@@ -283,3 +289,5 @@ private const(char)[] initilizePayload(ref return char[maxMsgLen] payload, scope
283
289
(() @trusted => memcpy(payload.ptr, msg.ptr, msg.length))();
284
290
return payload[0 .. msg.length];
285
291
}
292
+
293
+ }
0 commit comments