fork download
  1. #include <exception>
  2. #include <stdexcept>
  3. #include <iostream>
  4.  
  5. void handle_exceptions() {
  6. try {
  7. throw;
  8. } catch(const std::runtime_error& err) {
  9. std::cout << "Handling runtime error " << err.what();
  10. } catch(const std::logic_error& err) {
  11. std::cout << "Handling logic error " << err.what();
  12. }
  13. }
  14.  
  15. void my_function() {
  16. throw std::runtime_error("HI");
  17. }
  18.  
  19. int main() {
  20. try {
  21. my_function();
  22. } catch(...) { handle_exceptions();}
  23. }
Success #stdin #stdout 0.02s 2812KB
stdin
Standard input is empty
stdout
Handling runtime error HI