fork download
  1. #include <exception>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. class SomeException:
  6. public std::exception
  7. {
  8. std::string
  9. message;
  10. public:
  11. SomeException( const std::string &message ):
  12. message( message )
  13. {
  14. }
  15.  
  16. const char *what(void) const throw() override
  17. {
  18. return message.c_str();
  19. }
  20. };
  21.  
  22. int main(void)
  23. {
  24. try
  25. {
  26. throw SomeException( "abcdef" );
  27. }
  28. catch( const std::exception &exception )
  29. {
  30. std::cout
  31. << exception.what()
  32. << std::endl;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
abcdef