Python Exception Handling

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Exception handling enables you handle errors gracefully and do something meaningful about it. Like display a message to user if intended file not found. Python handles exception using try.. except ..  block.

Syntax:

Note:  Statements under the else  clause run only when no exception is raised.

Note: Statements in finally  block will run every time no matter exception occurs or not.

Now let’s take an example.