Advertisement
Guest User

Untitled

a guest
Dec 12th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.58 KB | None | 0 0
  1. import std.stdio;
  2. import core.exception;
  3.  
  4. void foo()
  5. {
  6.   scope(exit) throw new AssertError("Assert 2");
  7.   throw new AssertError("Assert 1");
  8. }
  9.  
  10. void printThrowable(Throwable t)
  11. {
  12.   writeln(t.msg);
  13.   if (t.next)
  14.   {
  15.     writeln("printing chain:");
  16.     printThrowable(t.next);
  17.   }
  18.   if (cast(Error)t)
  19.   {
  20.     auto e = cast(Error)t;
  21.     if (e.bypassedException)
  22.     {
  23.       writeln("printing bypassed:");
  24.       printThrowable(e.bypassedException);
  25.     }
  26.   }
  27.  
  28. }
  29.  
  30. void main()
  31. {
  32.   try
  33.   {
  34.     foo();
  35.   }
  36.   catch (Throwable t)
  37.   {
  38.     t.printThrowable;
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement