Message169340
| Author |
rhettinger |
| Recipients |
alex, ncoghlan, rhettinger |
| Date |
2012年08月29日.05:35:26 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1346218527.53.0.439956211278.issue15806@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Hmm, the __exit__ method was doing exact matches by exception type, so KeyError wouldn't match LookupError or Exception.
There are probably a number of ways to fix this, but it may be easiest to use the builtin exception catching mechanisms:
class Ignore:
''' Context manager to ignore particular exceptions'''
def __init__(self, *ignored_exceptions):
self.ignored_exceptions = ignored_exceptions
def __enter__(self):
return self
def __exit__(self, exctype, excinst, exctb):
if exctype is not None:
try:
raise
except self.ignored_exceptions:
return True |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2012年08月29日 05:35:27 | rhettinger | set | recipients:
+ rhettinger, ncoghlan, alex |
| 2012年08月29日 05:35:27 | rhettinger | set | messageid: <1346218527.53.0.439956211278.issue15806@psf.upfronthosting.co.za> |
| 2012年08月29日 05:35:27 | rhettinger | link | issue15806 messages |
| 2012年08月29日 05:35:26 | rhettinger | create |
|