fork download
  1. // exceptions
  2. #include <iostream>
  3. using namespace std;
  4. class C {
  5. public:
  6. string srch(int &i) {
  7. if (i == 0) { //found
  8. cout << "got it: " << i << endl; return "i";
  9. }
  10. throw std::exception();
  11.  
  12. }
  13.  
  14. };
  15.  
  16. int main () {
  17. C c = C();
  18. int i = 2;
  19. int j = 0;
  20. try
  21. {
  22. c.srch(j);
  23. c.srch(i);
  24. }
  25. catch (const std::exception &e) {
  26. cout << "An exception occurred. Exception Nr. " << e.what() << '\n';
  27. }
  28. return 0;
  29. }
  30.  
  31.  
  32.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
got it: 0
An exception occurred. Exception Nr. std::exception