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

# · D · 33 lines · 27 code · 6 blank · 0 comment · 3 complexity · 5fb4a93081e8f1476fdaf019dfbdf0a8 MD5 · raw file

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