Exception Handling in Python
In Python, exceptions are errors that get triggered automatically. However, exceptions can be forcefully triggered and handled through program code.
Sometimes while executing a Python program, the program does not execute at all or the program executes but generates unexpected output or behaves abnormally. These occur when there are syntax errors, runtime errors or logical errors in the code.
If the rules of the particular programming language have not been followed while writing a program, an error occurs called Syntax error.
These errors are also known as parsing errors.
On encountering a syntax error, the interpreter does not execute the program unless we rectify the errors, and save and rerun the program.
If a syntax error is encountered in shell mode, python will display an error message immediately.
When a syntax error is encountered while running a program in script mode, a dialog box specifying the name of the error and a small description about the error are displayed.