Chained Catch Statements
Mantis
mail.mantis.88 at gmail.com
Mon Jan 30 06:59:11 PST 2012
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;
}
More information about the Digitalmars-d-learn
mailing list