Python Tutorial
Try Catch in Python

Hello, Guy’s Welcome To The Another Python Tutorial Article. In This Article, We Will Learn What is Try-Catch  In Python Programming Language.

What is Try-Catch?

Try-Catch is a Pre-defined Keyword In Python That Help You To Display The Error In Your Code And Your Existing Working Code Are Run Properly.

Also Read:- How To Take Input From User In Python

In Other Word, If You Create a Division Program In Python And Give Input. For Example, 1 Divide By 0. So We Know That 0 Can not Be Divided By 1. After This Division, You Write Some Print Function In Code. So If The Division Code Was Error Your Print Function That You Write After The Division Code Are Also Not Run. So Here The Try-Catch Keyword Use.

Try-Catch Syntax:-

try:

YOUR CODE

catch:

PRINT ERROR CODE

Question:-

Write a Program That Handel Division By 0

Program:-

x = 5

y = 0

try:

x/y

except Exception e:

print(e)

print(“Data That Run After Error”)

As You See That if 5/0 Give Us Error But Our Print Statement Was Work Properly. The Help Of Try-Except