Social Media

2/09/2019

Exception Handling

When a program terminates in abnormal condition, it is called exception.
The normal flow of the program is disturbed if any exception situation occurs in the program. The simplest example of exception situation is as:
e.g. Suppose we have to calculate a/b where a and b are entered by the user. What will  happen if user unknowingly enter the value of b 0. Exception will arise, because we can't divide any number by 0.

Our program will terminate from that line where exception is occurred.
Python has mechanism to deal such kinds of situation. We have 4 ways to deal with these kinds of situation.
  1. Python raise exception and also handle it implicitely
  2. Python raise raise exception and user handle it explicitely
  3. User raise exception and python handle it implicitely
  4. User raise exception and also handle it explicitely
 Exceptions can be of two types.
  1. Predefined Exceptions
  2. User defined Exceptions
The keywords that we will use in Exception handling are as follows:
  1. try
  2. except
  3. finally
  4. raise 



Be First to Post Comment !
Post a Comment