fork download
  1. #include <iostream>
  2. #include <stdexcept>
  3.  
  4. class my_ex: public std::logic_error {
  5. public:
  6. my_ex(const char* const what): std::logic_error(what) {}
  7. };
  8.  
  9. void just_throw_the_message(const char* const msg) {
  10. throw my_ex(msg);
  11. }
  12.  
  13. int main() {
  14. try {
  15. just_throw_the_message("I feel somewhat exceptional.");
  16. } catch (const std::exception& e) {
  17. std::cout << "exception caught: " << e.what() << std::endl;
  18. }
  19. return 0;
  20. }
Success #stdin #stdout 0s 4488KB
stdin
Standard input is empty
stdout
exception caught: I feel somewhat exceptional.