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