On Wednesday, May 29, 2013 14:36:18 Jakob Ovrum wrote: > Consider the following example: > > http://dpaste.dzfl.pl/a0595ddf > ---- > // Can throw, and we want to catch > int createTheVar(); > > // Can also throw, but we don't want to catch it here > int transform(int a); > > int foo() > { > const(int) i; > > try > { > i = createTheVar(); // Clearly not allowed > } > catch(Exception e) // For demo purposes > { > // Exception handling code > } > > return transform(i); > } > ----
Wrap the try-catch in a function. int foo() { int initI() { try return createTheVar(); catch(Exception e) return int.init; } const int i = initI(); return transform(i); } And as it's a nested function, you can even have access to foo's scope (or make it static if you don't need that). - Jonathan M Davis