Different types of exceptions can be caught : Exception type « Exceptions « C++ Tutorial






#include <iostream>
using namespace std;

void f(int test)
{
  try{
    if(test) 
       throw test;
    else 
       throw "Value is zero";
  }
  catch(int i) {
    cout << "Caught Exception #: " << i << '\n';
  }
  catch(const char *str) {
    cout << "Caught a string: ";
    cout << str << '\n';
  }
}

int main()
{
  cout << "Start\n";

  f(1);
  f(2);
  f(0);
  f(3);

  cout << "End";

  return 0;
}
Start
Caught Exception #: 1
Caught Exception #: 2
Caught a string: Value is zero
Caught Exception #: 3
End"








6.4.Exception type
6.4.1.Different types of exceptions can be caught
6.4.2.how to restrict the types of exceptions that can be thrown from a function.
6.4.3.Catch double exception
6.4.4.Catching class type exceptions
6.4.5.Catching Class Types