PageRenderTime 31ms CodeModel.GetById 18ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
D | 40 lines | 36 code | 4 blank | 0 comment | 0 complexity | b659d0ffe013ff596d881092d1eb3038 MD5 | raw file
 1module li_std_except_runme;
 2
 3import tango.core.Exception;
 4import tango.io.Console;
 5import li_std_except.Test;
 6
 7void main() {
 8  with (new Test()) {
 9    mixin(test("Exception", "throw_bad_exception"));
10    mixin(test("Exception", "throw_domain_error"));
11    mixin(test("Exception", "throw_exception"));
12    mixin(test("IllegalArgumentException", "throw_invalid_argument"));
13    mixin(test("NoSuchElementException", "throw_length_error"));
14    mixin(test("Exception", "throw_logic_error"));
15    mixin(test("NoSuchElementException", "throw_out_of_range"));
16    mixin(test("Exception", "throw_overflow_error"));
17    mixin(test("Exception", "throw_range_error"));
18    mixin(test("Exception", "throw_runtime_error"));
19    mixin(test("Exception", "throw_underflow_error"));
20  }
21}
22
23char[] test(char[] e, char[] f) {
24  return "if (!works!(" ~ e ~ ")(&" ~ f ~ ")) {\n" ~
25    "throw new Exception(\"" ~ f ~ " failed\");\n" ~
26  "}";
27}
28
29bool works(alias E, F)(F f) {
30  try {
31    try {
32      f();
33    } catch(E) {
34      return true;
35    }
36  } catch(Exception e) {
37    Cerr( "Received wrong exception: " ~ e.classinfo.name ).newline;
38  }
39  return false;
40}