30.01.2012 16:37, Jared пишет:
However, this doesn't seem to be possible in D.
Why not?

import std.stdio;

class Exception1 : Throwable { this( string s ) { super( s ); } }
class Exception2 : Throwable { this( string s ) { super( s ); } }

void foo() {
    throw new Exception1( "foo" );
}

void bar() {
    throw new Exception2( "bar" );
}

int main() {
    enum tryBar = false;

    try {
        static if( tryBar ) {
            bar();
        } else {
            foo();
        }
    } catch( Exception1 e1 ) {
        writeln( "First catch block: ", e1.msg );
    } catch( Exception2 e2 ) {
        writeln( "Second catch block: ", e2.msg );
    }

    return 0;
}

Reply via email to