fork(31) download
  1. #include <iostream>
  2.  
  3. class ExceptionBase {
  4. };
  5.  
  6. class MyException : public ExceptionBase {
  7. };
  8.  
  9. int main()
  10. {
  11. try
  12. {
  13. throw MyException();
  14. }
  15. catch (MyException const& e) {
  16. std::cout<<"catch 1"<<std::endl;
  17. }
  18. catch (ExceptionBase const& e) {
  19. std::cout<<"should not catch 1"<<std::endl;
  20. }
  21.  
  22. ////////
  23. try
  24. {
  25. throw MyException();
  26. }
  27. catch (ExceptionBase const& e) {
  28. std::cout<<"catch 2"<<std::endl;
  29. }
  30. catch (...) {
  31. std::cout<<"should not catch 2"<<std::endl;
  32. }
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 2812KB
stdin
Standard input is empty
stdout
catch 1
catch 2