MAHEEN
ROLL# 1495
TOPIC:-
EXCEPTION & EXCEPTION
HANDLING
An Exception is a problem that arises during the execution
of a program.
C++ exception is a response to an exceptional
circumstances that arises while a program is running.
E.G. An attempt to divide by zero.
This disrupts the normal flow of the program’s instructions
when an error occurs within a method the method creates
an object and hands it off to the runtime system.
What is exception?
Programmers use design reviews and exhaustive testing to find logic errors.
Exceptions are different, however.You can’t eliminate exceptional
circumstances; you only can prepare for them.
Programs can respond to the errors, using one of following approaches.
1. Crash the program.
2. Inform the user and exit gracefully.
3. Inform the user and allow the user to try to recover and continue.
4. Take corrective action and continue without disturbing the user.
Although it is not necessary or even desirable for every program you write
to automatically and silently recover from all exceptional
circumstances, it is clear that you must do better than crashing.
Handling Unexpected errors:
The process of exception handling allows us to
treat problems that can occur in a program in a
more organized way.The advantage of exception
handling is a higher automation code.
Exception handling is made by try and catch
blocks and can be thrown by throw.
Exceptional Handling:-
Try – detects the part of the code where we are
looking for exceptions,
Catch – is used to determine the type of
exceptions and how the caught exceptions
will be handled
throw – it can be called from anywhere in the
program code in a try ...
If an error is thrown and not caught in a try ...
catch block it will cause an abrupt
termination of the program
1. Writing a simple try-catch
Maheen oop
Maheen oop
Maheen oop

Maheen oop

  • 2.
  • 3.
  • 4.
    An Exception isa problem that arises during the execution of a program. C++ exception is a response to an exceptional circumstances that arises while a program is running. E.G. An attempt to divide by zero. This disrupts the normal flow of the program’s instructions when an error occurs within a method the method creates an object and hands it off to the runtime system. What is exception?
  • 5.
    Programmers use designreviews and exhaustive testing to find logic errors. Exceptions are different, however.You can’t eliminate exceptional circumstances; you only can prepare for them. Programs can respond to the errors, using one of following approaches. 1. Crash the program. 2. Inform the user and exit gracefully. 3. Inform the user and allow the user to try to recover and continue. 4. Take corrective action and continue without disturbing the user. Although it is not necessary or even desirable for every program you write to automatically and silently recover from all exceptional circumstances, it is clear that you must do better than crashing. Handling Unexpected errors:
  • 6.
    The process ofexception handling allows us to treat problems that can occur in a program in a more organized way.The advantage of exception handling is a higher automation code. Exception handling is made by try and catch blocks and can be thrown by throw. Exceptional Handling:-
  • 8.
    Try – detectsthe part of the code where we are looking for exceptions, Catch – is used to determine the type of exceptions and how the caught exceptions will be handled throw – it can be called from anywhere in the program code in a try ... If an error is thrown and not caught in a try ... catch block it will cause an abrupt termination of the program
  • 9.
    1. Writing asimple try-catch