How to initialize immutable variables with an expression that throws an exception to catch?

FeepingCreature feepingcreature at
Fri Apr 3 06:56:27 UTC 2020

Consider the following code:

struct S { }
   S s = void;
     s = fun();
   catch (Exception)

Now you change S to be immutable.

How are you supposed to initialize s? You can't assign to it 

Assume that we explicitly don't want to pull the call into the 
try body, for instance because we want exceptions from call to 
not be caught.

The only way I've found is to make fun() return Algebraic!(S, 
Exception) but that's kind of ugly and bypasses a basic language 

Maybe D could allow to initialize an immutable variable from the 
try{} body if the catch{} body is statically known to exit by 

More information about the Digitalmars-d mailing list