Try/Catch with version condition

Adam D. Ruppe destructionator at gmail.com
Tue Apr 9 15:03:03 UTC 2019


On Tuesday, 9 April 2019 at 14:43:54 UTC, foo wrote:
> But then that requires too much code duplication.
> What would be the best way to do this?

I'd simply put the try {} body into a helper function, then make 
the versions just call that function.


void helper() {
    throw new Exception("");
}

version(foo) {
   try helper();
   catch(Exception) {}
} else {
   helper();
}


Remember that with D's nested functions, you can define helper 
functions just about anywhere and containing the same stuff you'd 
use directly.


More information about the Digitalmars-d mailing list