fork(2) download
  1. #include <iostream>
  2.  
  3. class Exception { public: virtual char const *origin() { return "something else."; } };
  4. class ExDivByZero : public Exception { public: char const *origin() { return "Divided by zero."; } };
  5. class ExBadArgument : public Exception { public: char const *origin() { return "Bad argument."; } };
  6. class ExCannotOpen : public Exception { public: char const *origin() { return "Cannot open."; } };
  7.  
  8. int main() {
  9. for(;;) {
  10. char c;
  11. if (std::cin >> c, c == 'd')
  12. break;
  13. try {
  14. switch (c) {
  15. case 'a':
  16. throw ExDivByZero();
  17. break;
  18. case 'b':
  19. throw ExBadArgument();
  20. break;
  21. case 'c':
  22. throw ExCannotOpen();
  23. break;
  24. }
  25. } catch (Exception &e) {
  26. std::cerr << e.origin() << std::endl;
  27. }
  28. }
  29. return 0;
  30. }
  31. /* end */
  32.  
Time limit exceeded #stdin #stdout 5s 2896KB
stdin
Standard input is empty
stdout
Standard output is empty