3 ms·
I personally have a hard time understanding std::error_code. Specifically I can't figure out when std::generic_category vs std::system_category should be used,
by Thorrez 7y ago
I personally have a hard time understanding std::error_code. Specifically I can't figure out when std::generic_category vs std::system_category should be used, and I worry that confusion between the 2 of them will lead to confusing and inconsistent APIs where it's hard to predict what error_code will be returned in what situation.
- vlovich123 7y agostd::system_category and std::generic_category are generally the same on non-Windows platforms. std::system_category on Windows is any Windows error (HRESULT, GetLastError, etc) and std::generic_category always represents errno. So for cross-platform APIs that exist on both you'll generally use std::generic_category as the API is usually defined to modify errno in the case of an error. For Windows-only APIs use std::system_category.