article
menu_book Article

Using the try-except Block in Python: Handling Exceptions Gracefully

Get The Most Affordable Hosting in the World!

Starting at just $1.87/month — fast, reliable & secure. Free CDN included.

rocket_launch Get Started

You can also use the except statement with no exceptions defined as follows −

try: You do your operations here ...................... except: If there is any exception, then execute this block. ...................... else: If there is no exception then execute this block.

This kind of a try-except statement catches all the exceptions that occur. Using this kind of try-except statement is not considered a good programming practice though, because it catches all exceptions but does not make the programmer identify the root cause of the problem that may occur.

You can also use the same except statement to handle multiple exceptions as follows −

try: You do your operations here ...................... except(Exception1[, Exception2[,...ExceptionN]]]): If there is any exception from the given exception list, then execute this block. ...................... else: If there is no exception then execute this block.
 
 
The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.

Was this answer helpful?

favorite 1 Users Found This Useful  ·  12 Votes

Powered by WHMCompleteSolution