Bad file descriptor in File destructor

Moritz Maxeiner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 13 04:29:27 PDT 2017


On Thursday, 13 July 2017 at 10:56:20 UTC, unDEFER wrote:
> Seems I have found. I must do:
> try{
>     File file;
>     try {
>         file = File(path);
>     }
>     catch (Exception exp)
>     {
>         return;
>     }
>
>     //Some actions with file
> }
> catch (ErrnoException)
> {
>     return;
> }

Well, yes, you can also encompass your entire function body in a 
try catch, though that makes your code somewhat hard to read[1]. 
With these many try/catches you may want to take a look at 
std.exception.collectException[2].

[1] https://en.wikipedia.org/wiki/Spaghetti_code
[2] https://dlang.org/phobos/std_exception.html#.collectException


More information about the Digitalmars-d-learn mailing list