Categories
Python Answers

How to properly ignore exceptions with Python?

Spread the love

Sometimes, we want to properly ignore exceptions with Python.

In this article, we’ll look at how to properly ignore exceptions with Python.

How to properly ignore exceptions with Python?

To properly ignore exceptions with Python, we can use try-except.

For instance, we write

try:
    f()
except: 
    pass

to call function f in the try block.

And any exceptions raised in f will be caught in the except block.

We just add pass in the except block to make it an empty block.

Conclusion

To properly ignore exceptions with Python, we can use try-except.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *