Error Handling Overview

In computer programs, some kind of errors are expected. We can simply read those errors and fix the problem. But some errors are bound to happen, usually related to user inputs or mismatch of specific conditions of the program.

Advertisements

Since, we know them already and knows that it would occur in some point in time during the execution, we can write codes that would respond to those errors.

These responses are error handling codes.

Python programming also supports error handling mechanism using certain keywords. These are

  1. try
  2. except
  3. else
  4. finally

Let us try to understand each one of them here.

Advertisements

Try block

The try block contain the actual program code which gets executed in a sequential manner until an error occurs.

Except block

The except block will catch the error that happened in the try block

Else block

If the try block is successful, then the program executes an else block if exists.

Finally

A piece of code that runs no matter what.

Advertisements

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.