PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/d/li_std_except_runme.2.d

#
D | 34 lines | 31 code | 3 blank | 0 comment | 0 complexity | dd08a051c3227023ffd91a1d1e0299fe MD5 | raw file
 1module li_std_except_runme;
 2
 3import std.exception;
 4import std.stdio;
 5import li_std_except.Test;
 6
 7void main() {
 8  with (new Test()) {
 9    enforce(works!(Exception)(&throw_bad_exception));
10    enforce(works!(Exception)(&throw_domain_error));
11    enforce(works!(Exception)(&throw_exception));
12    enforce(works!(Exception)(&throw_invalid_argument));
13    enforce(works!(Exception)(&throw_length_error));
14    enforce(works!(Exception)(&throw_logic_error));
15    enforce(works!(Exception)(&throw_out_of_range));
16    enforce(works!(Exception)(&throw_overflow_error));
17    enforce(works!(Exception)(&throw_range_error));
18    enforce(works!(Exception)(&throw_runtime_error));
19    enforce(works!(Exception)(&throw_underflow_error));
20  }
21}
22
23bool works(alias E, F)(F f) {
24  try {
25    try {
26      f();
27    } catch(E) {
28      return true;
29    }
30  } catch(Exception e) {
31    writefln( "Received wrong exception: %s", e.classinfo.name );
32  }
33  return false;
34}