MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

C++ language

Exception Handling in C++
Previous Home Next

Exception means run time error. To handle run time error, we use exception handling. Exception handling provides us the facility to transfer control from one part of program to another.

To handle run time error we use 3 keywords:-

  1. Try
  2. Catch
  3. Throw
  1. Try:- Try block contains the code for which exception will occur. This block followed by one or more catch block.
  2. Catch:- Catch block is use to handle the exception.
  3. Throw:- Throw keyword is use to raise the unchecked exception. Run time error is thrown by using throw keyword from inside try block.

Syntex:

try
{
   no. of statements and logic
}
catch (Exception E1)
{
   no. of statements
}
catch (Exception E2)
{
   no. of statements
}
catch (Exception En)
{
   no. of statements
}

 

Example:

# include <iostream.h>
# include <conio.h>
void main ()
{
   int a,b,c ;
  Cout << "Enter the value of variable a";
  Cin >> a ;
  Cout << "Enter the value of variable b";
  Cin >> b ;
  try
    {
      c = a/b ;
     
      Cout << c ;
    }
  else
   {
      throw (a/b) ;
   }

  catch (exception e)
   {
       Cout << "Divide by zero is an error";
   }
}
Output
Enter the value of variable a  10
Enter the value of variable b  0

Divide by zero is an error
Previous Home Next