Small fix: arithmetic_analysis/newton_method.py by dhruvmanila · Pull Request #2498 · TheAlgorithms/Python · GitHub
Skip to content

Small fix: arithmetic_analysis/newton_method.py - #2498

Merged
cclauss merged 1 commit into
TheAlgorithms:masterfrom
dhruvmanila:patch-error
Sep 27, 2020
Merged

cclauss merged 1 commit into
TheAlgorithms:masterfrom
dhruvmanila:patch-error

Conversation

@dhruvmanila

Copy link
Copy Markdown
Member

Small fix to arithmetic_analysis/newton_method.py

When you raise inside an except block you will get two traceback.

>>> try:
...     a = 1/0
... except ZeroDivisionError:
...     raise ZeroDivisionError("Not possible")
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
ZeroDivisionError: Not possible

Why? the except block is used to handle the exceptions, if you want to raise an exception inside it you need to use the from clause like so:

>>> try:
...     a = 1/0
... except ZeroDivisionError:
...     raise ZeroDivisionError("Not possible") from None
...
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
ZeroDivisionError: Not possible

Describe your change:

  • Fix a bug or typo in an existing algorithm?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Comment thread arithmetic_analysis/newton_method.py
@cclauss cclauss closed this Sep 27, 2020
@cclauss cclauss reopened this Sep 27, 2020
@cclauss cclauss closed this Sep 27, 2020
@cclauss cclauss reopened this Sep 27, 2020
@cclauss
cclauss merged commit 187e8cc into TheAlgorithms:master Sep 27, 2020
@TravisBuddy

Copy link
Copy Markdown

@dhruvmanila
dhruvmanila deleted the patch-error branch September 28, 2020 04:48
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
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

Successfully merging this pull request may close these issues.

3 participants