-
Notifications
You must be signed in to change notification settings - Fork 127
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
Use specific exception classes where appropriate #811
Comments
While I agree that HOOMD probably overuses |
|
There is another patten we should fix when we work on this issue. In most places, HOOMD issues an error and then raises an exception. Example:
Instead, this should not call the error and put the descriptive string in the exception. I've been using ostringstream for this when I update it, but it is cumbersome. Is there a better way? Example:
|
@joaander Changing that "log error and except" pattern would be a great idea. I think |
I have made slow progress in converting the error, then throw calls to just a throw with the full error description as outlined above. There are still many places in the codebase to check and convert. We should make a concerted effort to convert them all over before releasing 3.0.0. |
Description
I tried to read a file that doesn't exist with
sim.create_state_from_gsd
. Should GSD file reading errors beOSError
and/orFileNotFoundError
instead ofRuntimeError
?Proposed solution
Use another exception instead of
RuntimeError
, perhapsFileNotFoundError
orOSError
.Additional context
I think this may apply to other exceptions as well - we use
RuntimeError
pretty liberally in our code bases and it seems like it's a catch-all for things that have more specific causes. The docstring saysI frequently refer to this list of all built-in exceptions when choosing what to raise. It may be useful to other developers. https://docs.python.org/3/library/exceptions.html#exception-hierarchy
The text was updated successfully, but these errors were encountered: