fork download
  1. #include <iostream>
  2. using std::cout; using std::endl;
  3. #include <stdexcept>
  4. using std::invalid_argument;
  5.  
  6. #define N_VALID "is not a valid ID"
  7.  
  8. void function_throws()
  9. {
  10. throw invalid_argument(N_VALID);
  11. }
  12.  
  13. int main()
  14. {
  15. try
  16. {
  17. function_throws();
  18. }
  19. catch(const invalid_argument& ex)
  20. {
  21. cout << "invalid_argument: " << ex.what() << endl;
  22. }
  23. catch(const char *message)
  24. {
  25. cout << "const char*: " << message << endl;
  26. }
  27. }
  28.  
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
invalid_argument: is not a valid ID