I am trying to get on the screen: 1,2,3,4,5,6,7
, but I don't know how to order the catch(s) in my program. Is it possible to get this output by ordering the catches? Can you please explain how it works? I searched in many forums, but I have found nothing about that. Thank you so much.
#include <exception>
#include <string>
#include <iostream>
using namespace std;
class My_Exception : public exception {};
class something {};
void func1() { cout << "1" << endl; throw exception(" no t h ing "); }
void func2() { cout << "2" << endl; throw string(" 12345 "); }
void func3() { cout << "3" << endl; throw out_of_range(" abcde "); }
void func4() { cout << "4" << endl; throw ios::failure(" i o s "); }
void func5() { cout << "5" << endl; throw My_Exception(); }
void func6() { cout << "6" << endl; throw something(); }
void func7() { cout << "7" << endl; throw logic_error(" t r u e "); }
int main() {
try {
func1(); func2(); func3();
func4(); func5(); func6();
func7();
}
catch (My_Exception) {/*1*/ }
catch (exception) {/*2*/ }
catch (logic_error) {/*3*/ }
catch (string) {/*4*/ }
catch (...) {/*5*/ }
catch (out_of_range) {/*6*/ }
catch (ios::failure) {/*7*/ }
catch (something) {/*8*/ }
return 0;
}