I'd like to be able to know if my destructor is being called because an exception was thrown. Any way to do that?

I tried this: http://ideone.com/JbXH2w

(Pasted here for convenience):

import std.stdio, std.exception;

struct Catcher {
        ~this() {
                try {} catch (Exception e) {
                        writeln("Woooo!");
                        throw e;
                }
                scope (failure) {
                        writeln("Woooo woooo!");
                }
                writeln("Destructing...");
        }
}

void main() {
        scope (failure) writeln("Sensible");
        scope (exit) writeln("Always written");
        Catcher c1;
        scope auto c2 = Catcher();
        throw new Exception("Foobar");
}

Which does not print the "Wooo" lines, but does print all the others.

Reply via email to