PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. module li_std_except_runme;
  2. import tango.core.Exception;
  3. import tango.io.Console;
  4. import li_std_except.Test;
  5. void main() {
  6. with (new Test()) {
  7. mixin(test("Exception", "throw_bad_exception"));
  8. mixin(test("Exception", "throw_domain_error"));
  9. mixin(test("Exception", "throw_exception"));
  10. mixin(test("IllegalArgumentException", "throw_invalid_argument"));
  11. mixin(test("NoSuchElementException", "throw_length_error"));
  12. mixin(test("Exception", "throw_logic_error"));
  13. mixin(test("NoSuchElementException", "throw_out_of_range"));
  14. mixin(test("Exception", "throw_overflow_error"));
  15. mixin(test("Exception", "throw_range_error"));
  16. mixin(test("Exception", "throw_runtime_error"));
  17. mixin(test("Exception", "throw_underflow_error"));
  18. }
  19. }
  20. char[] test(char[] e, char[] f) {
  21. return "if (!works!(" ~ e ~ ")(&" ~ f ~ ")) {\n" ~
  22. "throw new Exception(\"" ~ f ~ " failed\");\n" ~
  23. "}";
  24. }
  25. bool works(alias E, F)(F f) {
  26. try {
  27. try {
  28. f();
  29. } catch(E) {
  30. return true;
  31. }
  32. } catch(Exception e) {
  33. Cerr( "Received wrong exception: " ~ e.classinfo.name ).newline;
  34. }
  35. return false;
  36. }