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