PageRenderTime 23ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

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

#
D | 33 lines | 27 code | 6 blank | 0 comment | 3 complexity | 5fb4a93081e8f1476fdaf019dfbdf0a8 MD5 | raw file
 1module catches_runme;
 2
 3import catches.catches;
 4
 5void main() {
 6  test({ test_catches(1); }, "C++ int exception thrown, value: 1");
 7  test({ test_catches(2); }, "two");
 8  test({ test_catches(3); }, "C++ ThreeException const & exception thrown");
 9
10  test({ test_exception_specification(1); }, "C++ int exception thrown, value: 1");
11  test({ test_exception_specification(2); }, "unknown exception");
12  test({ test_exception_specification(3); }, "unknown exception");
13
14  test({ test_catches_all(1); }, "unknown exception");
15}
16
17void test(void delegate() command, char[] expectedMessage) {
18  bool didntThrow;
19  try {
20    command();
21    didntThrow = true;
22  } catch (Exception e) {
23    if (e.msg != expectedMessage) {
24      throw new Exception("Failed to propagate C++ exception. Expected '" ~
25	expectedMessage ~ "', but received '" ~ e.msg ~ "'.");
26    }
27  }
28
29  if (didntThrow) {
30    throw new Exception("Failed to propagate C++ exception. Expected '" ~
31      expectedMessage ~ "', but no exception was thrown.");
32  }
33}