EXCEPTION HANDLING





Program

#include "iostream.h"
#include "conio.h"
using namespace std;
double divide(double a,double b)
{
try
{
if(!b) throw(b);
}
catch(double)
{
cout << "cannot divide by zero"; exit(1);

} return a/b;
}
int main() { cout << size="5">
Output

4
cannot divide by zero

Press any key to continue