Catch SystemError in portable code#15015
Conversation
This will ensure this catching works on Windows too, not just Unix.
| throw SysError("getting status of '%1%'", srcFile); | ||
| } catch (SysError & e) { | ||
| if (e.errNo == ENOENT || e.errNo == ENOTDIR) { | ||
| } catch (SystemError & e) { |
There was a problem hiding this comment.
Does this work? Above it's throwing a SysError with an errno, but where does the errno get converted to an std::errc that can be caught here?
There was a problem hiding this comment.
We now store a std::error_code (system_category) and it's comparable to a std::errc even on windows since fd0bcd9. In unix-like system_category is the same as generic_category, which is just the errno. On windows the comparison goes through the first overload of equivalent virtual function https://en.cppreference.com/w/cpp/error/error_category/equivalent.html, which implements a mapping from windows errors to POSIX ones (std::error_condition is implicitly constructible from std::errc: https://en.cppreference.com/w/cpp/error/error_condition/error_condition.html that uses the generic_category: https://en.cppreference.com/w/cpp/error/errc/make_error_condition.html)
Motivation
This will ensure this catching works on Windows too, not just Unix.
Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.