Skip to content

[DOC] Exceptions doc #10865

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

Merged
merged 9 commits into from
Jun 4, 2024
Merged

[DOC] Exceptions doc #10865

merged 9 commits into from
Jun 4, 2024

Conversation

BurdetteLamar
Copy link
Member

Free-standing document about exceptions.

@BurdetteLamar BurdetteLamar marked this pull request as draft May 29, 2024 17:31
@BurdetteLamar BurdetteLamar added the Documentation Improvements to documentation. label May 29, 2024
@BurdetteLamar
Copy link
Member Author

@peterzhu2118 (and anyone else): I've marked this as a draft while we discuss scope. I'm planning work on class Exception (class doc and methods doc), and on Kernel#raise. It may be best to add those to this PR and review all at once; on the other hand, that will make a biggish PR. Thoughts?

Copy link
Member

@peterzhu2118 peterzhu2118 left a comment

Choose a reason for hiding this comment

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

Do you have any plans to link this document from any existing documentation?

Comment on lines 347 to 352
If you are building a library or gem (or even if you're not),
it's good practice to start with a single “generic” exception class
(commonly an immediate subclass of StandardError or RuntimeError),
and have its other exception classes derive from that class.
This allows an exception handler to rescue the generic exception,
thus also rescuing all its derived exceptions.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is really a common or necessarily encouraged practice. Do have an example of where this is done?

Copy link
Member Author

Choose a reason for hiding this comment

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

Net::HTTP has most of its exceptions subclassed from HTTPClientError and HTTPServerError.

Copy link
Member

Choose a reason for hiding this comment

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

I feel like Net::HTTP is a special case, since all HTTP errors are of the 4xx class or 5xx class (for client and server errors, respectively). I don't think this this statement is generally true though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed.

@BurdetteLamar
Copy link
Member Author

Do you have any plans to link this document from any existing documentation?

Yes; at a minimum, from: the class doc for Exception; method doc for Kernel#raise.

@BurdetteLamar BurdetteLamar marked this pull request as ready for review May 31, 2024 18:13
@BurdetteLamar
Copy link
Member Author

@peterzhu2118, ready for you.

@peterzhu2118 peterzhu2118 merged commit 6b379b9 into ruby:master Jun 4, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements to documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants