Skip to content

Use more specific Exceptions - #258

Open
bendavis78 wants to merge 1 commit into
paramiko:mainfrom
bendavis78:exception_cleanup
Open

bendavis78 wants to merge 1 commit into
paramiko:mainfrom
bendavis78:exception_cleanup

Conversation

@bendavis78

Copy link
Copy Markdown
Contributor

Changed instances of "raise Exception" to use more specific exception types (tests pass).

For example, when we want to parse a config, and handle only errors specific to config:

from paramiko import config
try:
    cfig = config.SSHConfig
    cfig.parse(open('~/.ssh/config'))
except config.Error:
    print "Error parsing config file"
except OSError:
    print "Error opening file"

Added:

  • paramiko._winapi.WindowsError(OSError)
  • paramiko.config.Error(Exception)

Used built-in exceptions where it made sense. For example:

  • Exception("not implemented ...") was replaced by NotImplemented("not implemented ...")
  • Exception("Unknown type ...") was replaced byValueError("Unknown type...")``. The classes being checked by isinstance() were passed as function parameters, hence ValueError instead of TypeError.

Changed instances of "raise Exception" to use more specific exception types

Added:

    * paramiko._winapi.WindowsError(OSError)
    * paramiko.config.Error(Exception)

Used built-in exceptions where it made sense.
@lndbrg

lndbrg commented Jan 30, 2014

Copy link
Copy Markdown
Contributor

Yes, this looks sane. It might be nice to have some test for this too (make sure that the correct exceptions are being raised). I don't think it's mergeable before the py3 switch though (see #236) since it might introduce breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants