how to restrict the types of exceptions that can be thrown from a function. : Exception type « Exceptions « C++ Tutorial






#include <iostream>
using namespace std;
   
void Xhandler(int test) throw(int, char, double){
  if(test==0) throw test; 
  if(test==1) throw 'a'; 
  if(test==2) throw 123.23; 
}
   
int main()
{
  cout << "start\n";
   
  try{
    Xhandler(0); 
  }
  catch(int i) {
    cout << "Caught an integer\n";
  }
  catch(char c) {
    cout << "Caught char\n";
  }
  catch(double d) {
    cout << "Caught double\n";
  }
   
  cout << "end";
   
  return 0;
}








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