Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <stdexcept>
  2. #include <string>
  3.  
  4. class MyException : public std::runtime_error
  5. {
  6. public:
  7. explicit MyException(const std::string& what_arg) :
  8. MyException(what_arg.data())
  9. {
  10. }
  11.  
  12. explicit MyException(const char* what_arg) :
  13. runtime_error(""),
  14. what_("MyException: ")
  15. {
  16. append(what_arg);
  17. }
  18.  
  19. inline const char* what() const noexcept
  20. {
  21. return what_.data();
  22. }
  23.  
  24. inline void append(const char* msg)
  25. {
  26. what_.append(msg);
  27. }
  28.  
  29. inline void append(const std::string& msg)
  30. {
  31. what_.append(msg);
  32. }
  33.  
  34. private:
  35. // As near as I can tell, there is no way to modify the what arg
  36. // of runtime_error, so I don't use it and make make my own what
  37. // arg here.
  38. //
  39. std::string what_;
  40. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement