Collateral exceptions seem to be broken
KennyTM~
kennytm at gmail.com
Sun May 8 13:38:36 PDT 2011
On May 9, 11 04:31, Andrej Mitrovic wrote:
> 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:
>
> object.Exception at test.d(26): thrown from foo
> object.Exception at test.d(38): thrown from bar #3
> object.Exception at test.d(38): thrown from bar #2
> object.Exception at test.d(38): thrown from bar #1
> object.Exception at test.d(38): thrown from bar #3
> object.Exception at test.d(38): thrown from bar #2
> object.Exception at test.d(38): thrown from bar #1
> object.Exception at test.d(38): thrown from bar #2
> object.Exception at test.d(38): thrown from bar #1
> object.Exception at test.d(38): thrown from bar #1
>
> Simply calling writeln(e) will work:
> void main()
> {
> try
> {
> foo();
> }
> catch (Exception e)
> {
> writeln(e);
> }
> }
>
> writes:
> object.Exception at test.d(27): thrown from foo
> object.Exception at test.d(39): thrown from bar #3
> object.Exception at test.d(39): thrown from bar #2
> object.Exception at test.d(39): thrown from bar #1
>
> However that doesn't help if you want to iterate through the
> exceptions one at a time.
Not reproducible on OS X with druntime on git master. I get
object.Exception at y.d(24): thrown from foo
----------------
5 y 0x000020b6 void y.foo() + 86
6 y 0x00002036 _Dmain + 14
<<rest of stack trace omitted>>
object.Exception at y.d(36): thrown from bar #3
----------------
5 y 0x00002141 void y.bar(int) + 105
6 y 0x000020d0 void y.foo() + 112
7 y 0x00002036 _Dmain + 14
<<rest of stack trace omitted>>
object.Exception at y.d(36): thrown from bar #2
----------------
5 y 0x00002141 void y.bar(int) + 105
6 y 0x00002160 void y.bar(int) + 136
7 y 0x000020d0 void y.foo() + 112
8 y 0x00002036 _Dmain + 14
<<rest of stack trace omitted>>
object.Exception at y.d(36): thrown from bar #1
----------------
5 y 0x00002141 void y.bar(int) + 105
6 y 0x00002160 void y.bar(int) + 136
7 y 0x00002160 void y.bar(int) + 136
8 y 0x000020d0 void y.foo() + 112
9 y 0x00002036 _Dmain + 14
<<rest of stack trace omitted>>
More information about the Digitalmars-d
mailing list