Order of Exception Handlers - C++ Statement

C++ examples for Statement:try catch

Description

Order of Exception Handlers

Demo Code

#include <iostream>
#include <stdexcept>

int main(int argc, const char *argv[]) {
  try {/*from ww w .  j  av  a  2  s  .com*/
    throw std::exception();
  }
  catch (std::exception &e) {
    std::cout << "Executed as first: " << e.what() << std::endl;
  }
  /* uncomment to see error
  catch (std::exception &e) {
    std::cout << "Executed IF first" << e.what() << std::endl;
  }*/

  return 0;
}

Result


Related Tutorials