Skip to content

ERR: catchall exception should be explicity and use Exception EAFP #7948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
immerrr opened this issue Aug 6, 2014 · 5 comments
Closed

ERR: catchall exception should be explicity and use Exception EAFP #7948

immerrr opened this issue Aug 6, 2014 · 5 comments
Labels
Error Reporting Incorrect or improved errors from pandas good first issue

Comments

@immerrr
Copy link
Contributor

immerrr commented Aug 6, 2014

EAFP is an acronym that stands for "easier to ask forgiveness than permission" and describes a principle behind the pythonic way of doing some operations that may fail:

try:
    do_smth()
except MyError:
    do_smth_otherwise()

as opposed to

if i_can_do_smth():
    do_smth()
else:
    do_smth_otherwise()

pandas sources use this a lot but often the exception is caught with except: which among other things intercept SystemExit and KeyboardInterrupt. Because of that it's possible that when you're trying to interrupt an operation it goes on simply choosing another code path.

There are valid use cases for carpet-catching excepts like that, most obvious ones being performing some cleanup and re-raising the error afterwards and catching all errors coming from evaluation of user-supplied code. In the rest of the cases except Exception: should be used instead.

@jreback jreback changed the title BUG: stop catching system errors when practising EAFP ERR: catchall exception should be explicity and use Exception EAFP Aug 6, 2014
@jreback jreback added this to the 0.15.1 milestone Aug 6, 2014
@cpcloud
Copy link
Member

cpcloud commented Aug 6, 2014

i think i have a branch lying around somewhere that traverses the entirety of pandas ast and lets you know where carpet bomb exceptions are

@cpcloud
Copy link
Member

cpcloud commented Aug 6, 2014

let me see if i can find it

@cpcloud
Copy link
Member

cpcloud commented Aug 6, 2014

though i suppose

grin 'except:'

is slightly less overkill :)

@cpcloud
Copy link
Member

cpcloud commented Aug 9, 2014

fwiw i would say that even catching Exception should be avoided where possible, since that hides bugs. there are places where pandas uses Exception for control flow, but i bet there are only a handful of those cases and i might argue that even then, being explicit about what your controlling is more clear

@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jbrockmendel
Copy link
Member

except: has been removed and nearly all the except Exception: are gone. closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas good first issue
Projects
None yet
Development

No branches or pull requests

5 participants