- In any programming language there are 2 types of errors are possible:
- Syntax Errors
- Runtime Errors
Syntax Errors
- The errors which occurs because of invalid syntax are called syntax errors.
Example
Python
x=10
if x==10
print("Hello")Output
PowerShell
SyntaxError: expected ':'Example
Python
print "Hello"Output
PowerShell
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?Note
- Programmer is responsible to correct these syntax error. Once all syntax errors are corrected then only program execution will be started.
Runtime Errors
- Runtime errors also known as exceptions.
- While executing the program if something goes wrong because of end user input or programming logic or memory problems … etc. then we will get runtime errors.
Example
Python
print(10/0)Output
PowerShell
ZeroDivisionError: division by zeroExample
Python
print(10/"ten")Output
PowerShell
TypeError: unsupported operand type(s) for /: 'int' and 'str'Example
Python
x==int(input("Enter Number:"))
print(x)Output
PowerShell
Enter Number:ten
ValueError: invalid literal for int() with base 10: 'ten'Note
- Exception handling concept applicable for runtime errors but not for syntax errors.
Exception
- An unwanted and unexpected event that disturbs normal flow of program is called exception.
- Some examples of exception are:
- ZeroDivisonError
- TypeError
- ValueError
- FileNotFoundError
- EOFError
- It is highly recommended to handle exceptions. The main objective of exception handling is graceful termination of the program.
Example
Python
print("Hello")
print(10/0)
print("Hi")Output
PowerShell
Hello
ZeroDivisionError: division by zeroException Hierarchy
- All exception classes are child classes of Base Exception i.e. every exception class extends Base Exception either directly or indirectly. Hence Base Exception acts as root for python exception hierarchy.
- Most of the times being a programmer we have to concentrate exception and its child classes.

Ungraded Questions
Get ready for an exhilarating evaluation of your understanding! Brace yourself as we dive into the upcoming assessment. Your active participation is key, so make sure to attend and demonstrate your knowledge. Let’s embark on this exciting learning journey together!