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

Need a detailed explanation of the below added line into documentation #117597

Closed
imrankuruvitta opened this issue Apr 7, 2024 · 3 comments
Closed
Labels
docs Documentation in the Doc dir

Comments

@imrankuruvitta
Copy link

imrankuruvitta commented Apr 7, 2024

consider this line "A class in an [except] clause is compatible with an exception if it is the same class or a base class thereof (but not the other way around — an except clause listing a derived class is not compatible with a base class)" which comes under errors and exception in python tutorial web page, please give clear explanation, because as it is not understandable by programmers who is new to python , added screenshot below
Screenshot (1)

Linked PRs

@imrankuruvitta imrankuruvitta added the docs Documentation in the Doc dir label Apr 7, 2024
@nineteendo
Copy link
Contributor

An except clause catches all errors of the specified class and its derived classes:

class ErrorA(Exception):
    pass

class ErrorAPlus(ErrorA):
    pass

class ErrorB(Exception):
    pass

for cls in [ErrorA, ErrorAPlus, ErrorB]:
    try:
        raise cls()
    except ErrorA:
        print("Caught error A")

Output:

Caught error A
Caught error A
Traceback (most recent call last):
  File "c:\Users\wanne\Desktop\test.py", line 12, in <module>
    raise cls()
ErrorB

Do you think the docs need to be updated with this?

@imrankuruvitta
Copy link
Author

Yes, correct

@erlend-aasland
Copy link
Contributor

erlend-aasland pushed a commit that referenced this issue Apr 9, 2024
…) (#117700)

(cherry picked from commit a05068d)

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

3 participants