4 ms·
I did something similar as a student, making my own exception class with std::ostream: throw exceptionC() << "error code: " << t; I often found myself having
by puffybuf 3y ago
I did something similar as a student, making my own exception class with std::ostream:
throw exceptionC() << "error code: " << t;
I often found myself having to format error strings for exceptions, so I thought I could just do it like cout in one line. I know now this is bad for i18n strings.
- rockwotj 3y agoGoogletest does this: http://google.github.io/googletest/primer.html#assertions http://google.github.io/googletest/primer.html#assertions
- codr7 3y agoWhy would you prefer that over: throw exceptionC("error code: ", t); ? Ever since perfect forwarding I've been using this pattern to get out of arrow hell: template <typename Arg, typename...Args> string to_string(Arg &&arg, Args &&...args) { stringstream buf; buf << arg; ((buf << std::forward<Args>(args)), ...); return buf.str(); }