C++ program to Throw multiple types of errors and received by a single Catch block

#include <iostream>
using namespace std;
int main()
{
  char msg[]="Divide by Zero error";
  int divisor,i;
  int num[]={45,67,100,34,121};
//5 data
  try
  {
    cout<<"Enter divisor: ";
    cin>>divisor;
    for(i=0;i<=5;i++)
    {
      if(divisor==0)
        throw msg;
      if(i==5)
        throw i;
      cout<<endl<<num[i]/divisor;
    }
  }
  catch(...) //single catch block
  {
    cout<<endl<<"Exception occurred...";
  }
  return 0;
}

1 comment:

  1. Oakley Titanium Glass | Titanium Artisan Glasses
    Oakley ford fiesta titanium Tintments of Gold, Silver, Orange, titanium guitar chords Gold, Green, Silver, White, Silver. Oakley Titanium snow peak titanium flask Glass: zinc oxide and titanium dioxide sunscreen Gold, Silver, Red, Gold, titanium dioxide Purple, $2.00 · ‎In stock

    ReplyDelete