Exception
can be said to be any abnormal condition in a program resulting to the
disruption in the flow of the program.
Exception in a code can also be handled. In case it is not handled, then the code is not executed further and hence execution stops when exception occurs.
Why use Exceptions?
1. try:
2. malicious code
3. except Exception1:
4. execute code
5. except Exception2:
6. execute code
7. ....
8. ....
9. except ExceptionN:
10. execute code
11. else:
12. In case of no exception, execute the else block code.
To learn more about Python at TCCI
Call us @ 9825618292
Visit us @ www.tccicomputercoaching.com
Exception in a code can also be handled. In case it is not handled, then the code is not executed further and hence execution stops when exception occurs.
Why use Exceptions?
Exceptions are convenient in many ways for handling errors and special
conditions in a program. When you think that you have a code which can
produce an error then you can use exception handling.
Common Exceptions
- ZeroDivisionError: Occurs when a number is divided by zero.
- NameError: It occurs when a name is not found. It may be local or global.
- IndentationError: If incorrect indentation is given.
- IOError: It occurs when Input Output operation fails.
- EOFError: It occurs when end of the file is reached and yet operations are being performed.
1. try:
2. malicious code
3. except Exception1:
4. execute code
5. except Exception2:
6. execute code
7. ....
8. ....
9. except ExceptionN:
10. execute code
11. else:
12. In case of no exception, execute the else block code.
To learn more about Python at TCCI
Call us @ 9825618292
Visit us @ www.tccicomputercoaching.com
No comments:
Post a Comment