Advertisement
Guest User

Untitled

a guest
May 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <exception>
  2. #include <iostream>
  3. #include <string>
  4. class CCoolException : public std::exception{
  5. public:
  6. explicit CCoolException(const char* _description): description(_description){}
  7. ~CCoolException(){std::cout << "~CCoolException" << std::endl;}
  8. virtual char const* what() const override { return description.c_str();}
  9. private:
  10. std::string description;
  11.  
  12. };
  13.  
  14. void f (){
  15. throw CCoolException("That's cool");
  16. }
  17. void g() {
  18. throw std::exception("Not cool");
  19. }
  20.  
  21. int main(){
  22. try{
  23. f();
  24. g();
  25. } catch (std::exception& e) {
  26. std::cout << e.what() << std::endl;
  27. return 1;
  28. } catch (...){
  29. std::cout << "Three dots" << std::endl;
  30. return 1;
  31. }
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement