fork download
  1. #include <iostream>
  2. #include <stdexcept>
  3.  
  4. class IntArray
  5. {
  6. public:
  7. IntArray(int size)
  8. {
  9. if (size < 0)
  10. {
  11. throw std::invalid_argument("Bad size");
  12. }
  13. if (size > 10)
  14. {
  15. throw std::out_of_range("Out of range");
  16. }
  17. }
  18. };
  19.  
  20. int main()
  21. {
  22. try
  23. {
  24. IntArray a(20);
  25. }
  26. catch (const std::invalid_argument& ex)
  27. {
  28. std::cout << "invalid arg: " << ex.what() << std::endl;
  29. }
  30. catch (const std::out_of_range& ex)
  31. {
  32. std::cout << "out of range: " << ex.what() << std::endl;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
out of range: Out of range