Supposing I have these functions defined somewhere:
std::string ws_to_s(const wchar_t*);
std::string ws_to_s(const std::wstring&);
std::wstring s_to_ws(const char*);
I wrote this class:
class runtime_error_w : public std::runtime_error {
public:
runtime_error_w() = default;
runtime_error_w(const wchar_t* what_arg)
: runtime_error(ws_to_s(what_arg)) { }
runtime_error_w(const std::wstring& what_arg)
: runtime_error(ws_to_s(what_arg)) { }
virtual const std::wstring what_w() const noexcept {
return ws_to_s(what());
}
};
So far this worked for me, but is there any problem with this approach?
Notice that what_w()
returns a std::string
object, not a const char*
.