-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[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
[DOC] Exceptions doc #10865
Conversation
@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? |
There was a problem hiding this 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?
doc/exceptions.md
Outdated
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
Yes; at a minimum, from: the class doc for Exception; method doc for Kernel#raise. |
@peterzhu2118, ready for you. |
Free-standing document about exceptions.