Skip to content
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

avoid url error exception #10887

Merged
merged 1 commit into from
Aug 14, 2018
Merged

Conversation

kouml
Copy link
Contributor

@kouml kouml commented Aug 10, 2018

Summary

To Avoid falling into url error exception, I changed the order of exceptions.

Related Issues

PR Overview

  • This PR requires new unit tests [y/n] (make sure tests are included)
  • This PR requires to update the documentation [y/n] (make sure the docs are up-to-date)
  • This PR is backwards compatible [y/n]
  • This PR changes the current API [y/n] (all API changes need to be approved by fchollet)

in

from urllib.error import URLError, HTTPError
try:
    raise URLError(reason="test")
except URLError as e:
    print("URL_Error")
    pass
except HTTPError as e:
    print("HTTP Error")
    pass
try:
    raise HTTPError(url="example.com", code=200, msg="test", hdrs=None, fp=None)
except URLError as e:
   print("URL_Error")
   pass
except HTTPError as e:
   print("HTTP Error")
   pass

out

URL_Error
URL_Error

I found that this code couldn't catch the HTTPError.
Because URLError is a subclass of HTTPError.

in

issubclass(HTTPError, URLError)

out

True

so, it should be changed order.

Copy link
Collaborator

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems reasonable, thanks for the PR!

@fchollet fchollet merged commit aa8d7f7 into keras-team:master Aug 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants