1
CONTENT :
• INTRODUCTION
• TRY ,THROW,CATCH
• SYNTAX
• EXAMPLE
2
INTRODUCTION :
Exception Handling :
It is a way of handling error which occure while executing
program.
Exception are run time unusual condition that a program may
encounter while executing..
This unusual condition includes condition such as “division by
zero”,””, or “running out of memory or disk space”.
3
CONTIN….
TRY :
It is one of the block in which we write the block of
statements which causes executions at run time in
other words try block always contains problematic
statements.
4
CONTIN….
THROW BLOCK:
5
A throw expression signals that an exceptional
condition—often, an error—has occurred in a try block
CONTIN….
CATCH BLOCK:
It is one of the block in which we write the block of
statements which will generates user friendly error
messages in other words catch block will suppose system
error messages.
6
In an program a block of code which can produce error is placed in try block
When an exception is detected in try it is thrown using throw statement
Syntax
try
{
throw exception;
}
catch(type argument)
{
}
SYNTAX
7
Relating exception handling with real life
If a Smartphone fails the
test
try throw
catch
8
PROGRAM
#include <iostream>
#include <conio.h>
using namespace std;
Int main()
{
 int dividend, divisor, quotient;
 try
 {
 cout << " Enter the dividend: ";
 cin >> dividend;
 cout << "Enter the divisor: ";
9
CONTIN…..
 cin >> divisor;
 if (divisor == 0)
 throw divisor;
 quotient = dividend / divisor;
 cout << "Quotient = " << quotient << endl;
 }
 catch (int x)
 {
cout << "Division by "<< x << endl;
 }
}
10
PROGRAM
exception.cpp
11
Thank you
12

Exception handling in c++

  • 1.
  • 2.
    CONTENT : • INTRODUCTION •TRY ,THROW,CATCH • SYNTAX • EXAMPLE 2
  • 3.
    INTRODUCTION : Exception Handling: It is a way of handling error which occure while executing program. Exception are run time unusual condition that a program may encounter while executing.. This unusual condition includes condition such as “division by zero”,””, or “running out of memory or disk space”. 3
  • 4.
    CONTIN…. TRY : It isone of the block in which we write the block of statements which causes executions at run time in other words try block always contains problematic statements. 4
  • 5.
    CONTIN…. THROW BLOCK: 5 A throwexpression signals that an exceptional condition—often, an error—has occurred in a try block
  • 6.
    CONTIN…. CATCH BLOCK: It isone of the block in which we write the block of statements which will generates user friendly error messages in other words catch block will suppose system error messages. 6
  • 7.
    In an programa block of code which can produce error is placed in try block When an exception is detected in try it is thrown using throw statement Syntax try { throw exception; } catch(type argument) { } SYNTAX 7
  • 8.
    Relating exception handlingwith real life If a Smartphone fails the test try throw catch 8
  • 9.
    PROGRAM #include <iostream> #include <conio.h> usingnamespace std; Int main() {  int dividend, divisor, quotient;  try  {  cout << " Enter the dividend: ";  cin >> dividend;  cout << "Enter the divisor: "; 9
  • 10.
    CONTIN…..  cin >>divisor;  if (divisor == 0)  throw divisor;  quotient = dividend / divisor;  cout << "Quotient = " << quotient << endl;  }  catch (int x)  { cout << "Division by "<< x << endl;  } } 10
  • 11.
  • 12.