Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdexcept>
- #include <string>
- class MyException : public std::runtime_error
- {
- public:
- explicit MyException(const std::string& what_arg) :
- MyException(what_arg.data())
- {
- }
- explicit MyException(const char* what_arg) :
- runtime_error(""),
- what_("MyException: ")
- {
- append(what_arg);
- }
- inline const char* what() const noexcept
- {
- return what_.data();
- }
- inline void append(const char* msg)
- {
- what_.append(msg);
- }
- inline void append(const std::string& msg)
- {
- what_.append(msg);
- }
- private:
- // As near as I can tell, there is no way to modify the what arg
- // of runtime_error, so I don't use it and make make my own what
- // arg here.
- //
- std::string what_;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement