How to use exceptions

kdevel kdevel at
Sat Aug 13 13:00:08 UTC 2022

On Friday, 12 August 2022 at 21:41:25 UTC, Christian Köstlin 

> which would enable something like
> ```d
>     return  s
>         .readText
>         .parseJSON
>         .contextWithException((UTFException e) {
>             return new Exception("Cannot process UTF-8 in 
> config file%s\n  %s".format(s, e.msg), e);
>         })
>         .contextWithException((FileException e) {
>             return new Exception("Cannot process config 
> file%s\n %s".format(s, e.msg), e);
>         });
> ```

This is not as DRY as it could be. Furthermore I would try 
implement the error handling completely outside the main 
execution path, ideally in a wrapper around a the old main 
function (renamed to main_). This approach becomes problematic if 
exceptions of the same class can be thrown from two functions of 
the chain.

Your code is printing e.msg. How to you localize that string?

More information about the Digitalmars-d-learn mailing list