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

Exceptions result in None being returned #4

Open
stevemolloy opened this issue Jan 10, 2018 · 2 comments
Open

Exceptions result in None being returned #4

stevemolloy opened this issue Jan 10, 2018 · 2 comments

Comments

@stevemolloy
Copy link
Contributor

I see that several exceptions are caught in order to return None, but I wonder if it might be possible to let the exception bubble up to the top instead. For example, in the case of trying to find the square root of a negative number, math.sqrt throws a ValueError, and it might be best to allow that exception to rise to the top of the code.

@zhangt58
Copy link
Owner

zhangt58 commented Jan 11, 2018

Yes, the present approach could be improved. I think we can add some code to test input parameter for each function, then throw out the much more precise message. For sqrt, return complex number when the input is negative would be nice. The returned None is just for the case of dealing with a large script, we can use is None or not to control the flow.

@zhangt58
Copy link
Owner

The issue of sqrt with negative is resolved by printing out a warning message (a3a1a4b), rather than throw out an exception, and the returned value is None. The same case for pyrpn command line interface, the invalid input will not stop the session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants