fork(1) download
  1. #include <iostream>
  2. #include <exception>
  3.  
  4. class E1 : public std::exception {};
  5. class E2 : public std::exception {};
  6.  
  7. int main() {
  8. try {
  9. throw E2();
  10. }
  11. catch( ... ) {
  12. //Do lots of complicated things here
  13. //Without the nesting, all the complicated things would have to be repeated twice
  14. try {
  15. throw;
  16. }
  17. catch( const E1 & e ) {
  18. std::cout << "E1\n";
  19. }
  20. catch( const E2 & e ) {
  21. std::cout << "E2\n";
  22. }
  23. }
  24. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
E2