Week 07 - Exception Handling
Week 07 - Exception Handling
Error Trapping
1. What is an exception?
2. Error types during coding
3. Python Built-in Exceptions
4. Create custom exceptions
5. How to handle errors?
Syntax Errors
Runtime Errors
Logical Errors
Easy to find
Occurs during the coding, testing and
development
Easily fixed
Program is released once the syntax
errors are fixed
By Nishan Saliya IIT 5
Syntax Error – Example 1
Hard to find
Algorithm errors
May visible during deployment not during coding,
testing and development
Can be fixed if figured properly
Program may be released with the logical error
Shows no errors!
Unpredicted behavior or output
try
try
The “try” throws an error
if it fails to execute a
code properly
The “except” captures
the error. Programmer
should handle it.
except
By Nishan Saliya IIT 15
Example Exception – Case 1
try
except
Specific Error
General Error
https://www.w3schools.com/python/python_try_except.asp
https://docs.python.org/3/tutorial/errors.html