On Friday, 15 March 2019 at 18:04:05 UTC, Bastiaan Veelo wrote:
In the code below (https://run.dlang.io/is/d0oTNi), ifThrown is inferred as un@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);} }(); }
Because the handlers may be unsafe. There is no safe overload of ifThrown. However you can work around this using @trusted.
