-
Notifications
You must be signed in to change notification settings - Fork 54
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
New Section Idea: Exceptions #66
Comments
I think having a discussion of exceptions and exception-handling would be really useful. It's actually super nice because we see various |
I agree @HardBoiled800 's section would be really valuable. It might best fit as a section in The Essentials of Python. If so, it would have to come after functions are introduced so that We should also take care to clarify for the reader that, despite their names, errors are exceptions. I recall this messing me up early on. Regarding the different types of exceptions, I think that we'd want to explicitly draw attention to Regarding assertions. The proper usage for def array_func(arr):
if arr.ndim != 4:
raise ValueError("`arr` must be a 4D array")
# some code here that should reduce
# `arr` to a 2D array
assert arr.ndim == 2, "`array_func(arr)` unexpectedly produced an array that is not 2D"
return arr Thus the initial check that the user provided a good array should raise a Regarding defining your own exception, this is a little bit tricky to cover as it requires an understanding of class inheritance, which isn't discussed until the very end of Module 3. It is also a rather advanced use case in the grand scheme of things. My impression is that one really doesn't need custom exceptions unless they are developing their own library. I'm open to discussion on this, but my thoughts are that we can make brief mention of this and then move on. As @davidmascharka pointed out, we already make use of exceptions in the text. It would be great if we could find the earliest moments where we reference them and add a parenthetical link to our formal discussion of exceptions. Lastly, it would be nice if we took time in this section to show readers how to understand stack traces and read error messages. |
All good points, @rsokl. Maybe it would be more appropriate to include a subsection in the Classes and Inheritance sections about defining your own exceptions, but keep the majority of the discussion on Exceptions in The Essentials of Python? Either way, I'll open up a new branch tonight and start to flesh out some of these ideas. |
Yeah, if we do want to touch on defining custom exceptions, it would need to be included separately in module 3. However, I'm not sure it meets the criterion of being "essential" Sounds good! I'll be happy to help. |
I agree with Ryan; custom exceptions don't seem essential (I've still never written one...) so I'm not sure a section is warranted. As far as other errors to cover go, the four you listed cover most use-cases. |
This is mostly covered in pull request #131 - I actually only just rediscovered this thread, so I may make a few edits to that request tonight to fully cover everything suggested here but it’s mostly there. |
One important aspect of Python that isn't discussed in PLYMI is Python's exceptions, what causes them, and how to create your own. I feel like an additional section in the Odds And Ends Module would be appropriate, discussing
I'd love to write up this section for the site. Is this something that you guys find appropriate? @rsokl @davidmascharka
The text was updated successfully, but these errors were encountered: