Python Try - Except

It is used for error handling in python, try is used for caught and except is used to handle these errors.

 

Python has some built-in exceptions which stop the program execution but these not affect the output result, so to reduce these error use try-except, which handle the process and program running properly.

There are two types of error which are handled by this:

  • Syntax Error

  • Exception

The program contains several types of exception which are handled by this:

  • IOError 

  • KeyboardInterrupt

  • ValueError 

  • EOFError 

  • ImportError 

By this program divided into the three parts:

  • try

  • Except

  • finally

We can easily understand it with the help of the given below example:

>>> Import sys       #use to get the type of exception

 

>>> list = [1,2,3]

>>> for a in list:

>>>     try:

>>>         print(“value is”)

>>>         result = a

>>>         break

>>>     catch:

>>>         print(“enter another value”)

>>> print(“the result is”, a)    

Now Python's basic topics are covered in the next tutorial we will cover the most important topic Python File Handling. If you have not read the previous tutorials then please first read all the video and go to the next topics file handling. 

Contact Us

Tel: (+91) 0120  4118730  

Time :   10 : 00  AM -  08 : 00 PM IST 

Registered address: G-69, Sector 63, 

 Noida - 201301, India

We Provide Services Across The different countries

USA    Australia   Canada   UK    UAE    Singapore   New Zealand    Malasia   India   Ireland   Germany

CodersArts is a Product by Sofstack Technology Solutions Pvt. Ltd.

  • CodersArts | Linkedin
  • Instagram