why is ifThrown un at safe?

Bastiaan Veelo Bastiaan at Veelo.net
Fri Mar 15 18:04:05 UTC 2019


In the code below (https://run.dlang.io/is/d0oTNi), ifThrown is 
inferred as un at safe. If instead I write the implementation of 
ifThrown out (after res2) then it is @safe. As far as I can see, 
there is no real difference. So why doesn't ifThrown work in this 
case, and can it be made to work?

Thanks!

void main() @safe
{
     import std.process;
     import std.exception;

      const res1 = execute(["clang", "-v", "-xc++", "/dev/null", 
"-fsyntax-only"], ["LANG": "C"])
         .ifThrown((e) @safe {
             import std.typecons : Tuple;
             return Tuple!(int, "status", string, "output")(-1, 
e.msg);
         }); // Fails

     const res2 = () {
         try
         {
             return execute(["clang", "-v", "-xc++", "/dev/null", 
"-fsyntax-only"], ["LANG": "C"]);
         }
         catch (Exception e)
         {
             import std.typecons : Tuple;
             return Tuple!(int, "status", string, "output")(-1, 
e.msg);
         }
     }();
}



More information about the Digitalmars-d-learn mailing list