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.
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.
- Python raise exception and also handle it implicitely
- Python raise raise exception and user handle it explicitely
- User raise exception and python handle it implicitely
- User raise exception and also handle it explicitely
- Predefined Exceptions
- User defined Exceptions
The keywords that we will use in Exception handling are as follows:
- try
- except
- finally
- raise
Be First to Post Comment !
Post a Comment