On 28.1.2016. 13:36, Niall Douglas wrote:
The way I've done it is to define a custom error code category per category of error throwing thing, thereby naturally extending C++ 11/Boost error codes. It may seem like an awful lot of boilerplate when you just want an enum really, but trust me that it is worth the effort - you get stuff like free error_code to exception throw to error_code conversions (you specifically need that machinery to return error codes from constructors)...
You don't need necessarily need to use std::error_code to 'return' errors from constructors...+ this practice is IMO a bit ugly (i.e. http://www.gotw.ca/publications/mill13.htm). In C++11 and later I think this can be solved more cleanly with static noexcept factory functions (which return outcomes/fallible_results/whatever), a move constructor and one variadic template constructor which forwards its arguments to the factory function(s) (so this pair of constructors handles any number of factory overloads) and forwards the result/return of the factory function to the move constructor...So, if you want noexcept construction you use a factory function or a constructor otherwise... -- "What Huxley teaches is that in the age of advanced technology, spiritual devastation is more likely to come from an enemy with a smiling face than from one whose countenance exudes suspicion and hate." Neil Postman