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
• 14,970 points
7 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 56,120 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 in Python by Nymeria
• 3,500 points
10 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 in Python by ariaholic
• 7,320 points
9 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 in Python by Mohammad
• 1,400 points
7 views
+2 votes
2 answers

How to make a laplacian pyramid using OpenCV python?

down voteacceptTheeThe problem is that you're iterating ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,710 points
948 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
20 views
+1 vote
1 answer
+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
• 56,120 points
77 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.