Throw an exception from a function and catch it : throw « Exceptions « C++ Tutorial






#include <iostream>
using namespace std;

// function prototypes.
float divide_number(float , float);

int main()
{
      float dividend,divisor,answer;
      try
         {
         dividend = 0;

         divisor = 0;

         answer = divide_number(dividend,divisor);
         }
         catch(...)
         {
                 cout << "oops, there is an error!";
         }

      return 1;
}
float divide_number(float num1, float num2)
{
  try
  {
    float answer;
    answer = num1/num2;
    return answer;
  }
  catch(...)
  {
         throw;
  }
}








6.2.throw
6.2.1.Throw an exception
6.2.2.Rethrowing an exception
6.2.3.Throw an exception from a function and catch it