How to declare immutable struct outside of try catch and reference it later

kdevel kdevel at vogtner.de
Sun Dec 3 22:33:40 UTC 2017


On Sunday, 3 December 2017 at 14:58:03 UTC, Basile B. wrote:
> In this case i'd go for a typed pointer, e.g
>
> ---
> immutable struct Configuration
> {
>     this(string){/*load some file...*/}
>     int value;
> }
>
> Configuration* config;
>
> void main()
> {
>     try config = new Configuration("config.sdl");
>     catch(Exception){}
>     // config.value = 42; // ok, read only
> }
> ---

When config is null, e.g. in case "load some file..." threw, you 
get a segfault. No error handling at all!


More information about the Digitalmars-d-learn mailing list