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,350 points
11 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
• 56,520 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,520 points
31 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,340 points
18 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
• 3,060 points
15 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,720 points
1,251 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 215 views
+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
• 56,520 points
130 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
• 56,520 points
128 views