qwerty787788

c++ exceptions are the best exceptions in the world!

Oct 16th, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class MyException : std::exception {
  4.     std::string msg;
  5. public:
  6.     MyException(std::string s) : msg(s) {
  7.  
  8.     }
  9.  
  10.     const char *what() {
  11.         return msg.c_str();
  12.     }
  13. };
  14.  
  15. int main() {
  16.  
  17.     try {
  18.         throw MyException("hello!");
  19.     } catch (std::exception &e) {
  20.         std::cerr << e.what() << std::endl;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment