fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int foo(int index)
  6. {
  7. switch(index)
  8. {
  9. case 1: return 3;
  10. case 2: throw string("text");
  11. case 3: throw bool(true);
  12. }
  13. throw logic_error("ololo");
  14. }
  15.  
  16. void example(int index)
  17. {
  18. try
  19. {
  20. const int result = foo(index);
  21. std::cout << "returned int: '" << result <<"'\n";
  22. }
  23. catch(const string& answer)
  24. {
  25. std::cout << "returned string: '" << answer <<"'\n";
  26. }
  27. catch(bool b)
  28. {
  29. std::cout << "returned bool: "
  30. << (b? "true" : "false")<<std::endl;
  31. }
  32. }
  33.  
  34. int main() {
  35.  
  36. example(1);
  37. example(2);
  38. example(3);
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
returned int: '3'
returned string: 'text'
returned bool: true