import std.stdio;
import std.conv;
import std.exception;
void main()
{
try
{
foo();
}
catch (Exception e)
{
for (Throwable t = e; t !is null; t = t.next)
{
writeln(t);
}
}
}
void foo()
{
try
{
throw new Exception("thrown from foo");
}
finally
{
bar(3);
}
}
void bar(int x)
{
try
{
throw new Exception(text("thrown from bar #", x));
}
finally
{
if (x > 1)
{
bar(x - 1);
}
}
}
DMD 2.052, XP 32bit:
[email protected](26): thrown from foo
[email protected](38): thrown from bar #3
[email protected](38): thrown from bar #2
[email protected](38): thrown from bar #1
[email protected](38): thrown from bar #3
[email protected](38): thrown from bar #2
[email protected](38): thrown from bar #1
[email protected](38): thrown from bar #2
[email protected](38): thrown from bar #1
[email protected](38): thrown from bar #1
Simply calling writeln(e) will work:
void main()
{
try
{
foo();
}
catch (Exception e)
{
writeln(e);
}
}
writes:
[email protected](27): thrown from foo
[email protected](39): thrown from bar #3
[email protected](39): thrown from bar #2
[email protected](39): thrown from bar #1
However that doesn't help if you want to iterate through the
exceptions one at a time.