How to properly ignore Exceptions

0 votes

When you just want to do a try-except without handling the exception, how do you do it in Python?

Is the following the right way to do it?

try:

 dosomthing()

except:

 pass

Jul 26, 2018 in Python by bug_seeker
• 15,510 points
614 views

1 answer to this question.

0 votes

try:

 doSomething()

except:

 pass

or

try:

 doSomething()

except Exception:

 pass

The difference is, that the first one will also catch KeyboardInterrupt, SystemExit and stuff like that, which are derived directly from exceptions.BaseException, not exceptions.Exception.

See documentation for details:

exceptions — http://docs.python.org/library/exceptions

answered Jul 26, 2018 by Priyaj
• 58,020 points

Related Questions In Python

0 votes
1 answer

How to get textual output when using exceptions in Python?

Hi, the answer is pretty simple.  Without the ...READ MORE

answered Jan 17, 2019 in Python by Nymeria
• 3,560 points
980 views
0 votes
1 answer

How to properly print timezone information using python?

Part of the problem here is that ...READ MORE

answered Feb 14, 2019 in Python by aryya
• 7,460 points
1,661 views
0 votes
1 answer

how to check for exceptions in a file?

try { if (!file.exists("TextFile1.txt")) throw ...READ MORE

answered Mar 20, 2019 in Python by Mohammad
• 3,230 points
660 views
0 votes
1 answer

How to catch multiple exceptions in one line in python?

From Python Documentation: An except clause may name multiple ...READ MORE

answered Dec 17, 2020 in Python by Gitika
• 65,770 points
5,105 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,441 views
0 votes
1 answer
+1 vote
1 answer

How to create plots using python matplotlib in IPython notebook?

I think you should try: I used %matplotlib inline in ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 58,020 points
1,582 views
+1 vote
1 answer

How can I map input to output without using dynamic()

Here am talking about my example you ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 58,020 points
1,014 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP