Skip to content

Commit 8c9d4a9

Browse files
committed
fixed an error
1 parent 1971f33 commit 8c9d4a9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

text/main/controlFlow/exceptions/exceptions.tex

+6-6
Original file line numberDiff line numberDiff line change
@@ -263,27 +263,27 @@
263263
After the block, we print \pythonil{"The program is now finished."}.
264264
This code is executed only if no uncaught \pythonilIdx{Exception} has left the \pythonil{try}-\pythonil{except} block.
265265
The output of the program given in \cref{exec:exceptions:try_except_str_index} shows that this is indeed the case:
266-
We first get the results of the successfull search for \pythonil{"Hello"}, followed by the output for the failed search.
266+
We first get the results of the successful search for \pythonil{"Hello"}, followed by the output for the failed search.
267267
The last line then is \textil{The program is now finished.}
268268

269269
\gitPythonAndErrorOutput{\programmingWithPythonCodeRepo}{06_exceptions}{try_multi_except.py}{--args format}{exceptions:try_multi_except}{%
270-
The handling of multiple errors, namely \pythonilIdx{DivisionByZero} and \pythonilIdx{ArithmeticError}, as well as what happens if a variable remains unassigned due to an error (a \pythonilIdx{NameError} is raised).}%
270+
The handling of multiple errors, namely \pythonilIdx{ZeroDivisionError} and \pythonilIdx{ArithmeticError}, as well as what happens if a variable remains unassigned due to an error (a \pythonilIdx{NameError} is raised).}%
271271
%
272272
In \cref{lst:exceptions:try_multi_except}, we revisit our new \pythonil{sqrt} function.
273273
This function will \pythonilIdx{raise} an \pythonilIdx{ArithmeticError} if its argument is non-finite or negative.
274274
This time, we want to compute~$\sqrt{\frac{1}{0}}$ and thus aim to store the result of \pythonil{sqrt(1 / 0)} in a variable \pythonil{sqrt_of_1_div_0}.
275275
We first declare the variable as a \pythonil{float}.
276276
Then, in a \pythonilIdx{try}-\pythonilIdx{except} block, we perform the actual computation: \pythonil{sqrt_of_1_div_0 = sqrt(1 / 0)}.
277277
Knowing that \pythonil{sqrt} might raise an \pythonilIdx{ArithmeticError}, we provide a corresponding \pythonilIdx{except} block.
278-
However, we also know that \pythonil{1 / 0} looks a bit dodgy, as we also try to intercept a potential \pythonilIdx{DivisionByZero} error.
278+
However, we also know that \pythonil{1 / 0} looks a bit dodgy, as we also try to intercept a potential \pythonilIdx{ZeroDivisionError} error.
279279
As you can see, we can have two independent \pythonilIdx{except} clauses.
280280

281281
So, which one will be executed?
282282
Certainly, $\frac{1}{0}$ is not finite, so \pythonil{sqrt} will raise an \pythonilIdx{Exception}.
283-
Then again, $\frac{1}{0}$ cannot be computed at all, so maybe we get a \pythonilIdx{DivisionByZero} error instead?
284-
We find that the \pythonilIdx{except} block for \pythonilIdx{DivisionByZero} is executed.
283+
Then again, $\frac{1}{0}$ cannot be computed at all, so maybe we get a \pythonilIdx{ZeroDivisionError} error instead?
284+
We find that the \pythonilIdx{except} block for \pythonilIdx{ZeroDivisionError} is executed.
285285
The reason is that in order to invoke \pythonil{sqrt(1 / 0)}, the \python\ interpreter must first compute the result of~\pythonil{1 / 0}.
286-
This computation raises \pythonilIdx{DivisionByZero} and \pythonil{sqrt} is never called.
286+
This computation raises \pythonilIdx{ZeroDivisionError} and \pythonil{sqrt} is never called.
287287

288288
This leads us to the question:
289289
If \pythonil{sqrt} is never called, then what will be assigned to \pythonil{sqrt_of_1_div_0}?

0 commit comments

Comments
 (0)