Skip to content

Commit 1971f33

Browse files
committed
added stack trace term
1 parent fe538a1 commit 1971f33

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

bibliography/bibliography.bib

+9
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,15 @@ @inbook{J2024PTOGBSI8IS12ESSSSIS
14271427
urldate = {2024-10-30},
14281428
}
14291429

1430+
@book{K1997FA,
1431+
xdata = {ser_taocp},
1432+
volume = {1},
1433+
title = {Fundamental Algorithms},
1434+
year = {1997},
1435+
edition = {3},
1436+
isbn = {0-201-89683-4},
1437+
}
1438+
14301439
@book{K1998SAS,
14311440
xdata = {ser_taocp},
14321441
volume = {3},

notation/terms.sty

+12
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ See \cref{sec:howFloatingPointNumbersWork}.%
166166
}%
167167
}%
168168
%
169+
%
170+
\newglossaryentry{stackTrace}{%
171+
name={stack trace},%
172+
description={%
173+
A stack trace gives information the way in which one function invoked another. %
174+
The term comes from the fact that the data needed to implement function calls is stored in a stack data structure~\cite{K1997FA}. %
175+
The data for the most recently invoked function is on top, the data of the function that called is right below, the data of the function that called that one comes next, and so on. %
176+
Printing a stack trace can be very helpful when trying to find out where an \pythonilIdx{Exception} occurred, see, for instance, \cref{sec:exceptions,lst:exceptions:use_sqrt_raise}.%
177+
}%
178+
}%
179+
%
180+
%
169181
\newglossaryentry{stderrs}{%
170182
name={standard error stream},%
171183
description={%

text/main/controlFlow/exceptions/exceptions.tex

+8-8
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168

169169
We collect the output of the program in \cref{exec:exceptions:use_sqrt_raise}.
170170
As can be seen, for \pythonil{0.0}, \pythonil{1.0}, \pythonil{2.0}, \pythonil{4.0}, and \pythonil{10.0}, the results are printed as anticipated.
171-
However, when the \pythonilIdx{for}~loop reaches \pythonilIdx{inf}, the program is terminated an the so-called \emph{stack trace} is written to the output.
171+
However, when the \pythonilIdx{for}~loop reaches \pythonilIdx{inf}, the program is terminated an the so-called \pgls{stackTrace} is written to the output.
172172

173173
It begins with the line \textil{Traceback (most recent call last):}.
174174
In the first line following this text, the source code file and the index of the line in that file where the \pythonilIdx{Exception} was originally raised are printed.
@@ -177,22 +177,22 @@
177177
Below that, we get to see the context of our \pythonil{sqrt} function:
178178
First, the path to its module is given (ending in \textil{06_exceptions/sqrt_raise.py}) and it is pointed out that the \pythonilIdx{Exception} was raised in line~15.
179179
This line of code is then also given, and it indeed is the one starting with \pythonil{raise ArithmeticError}.
180-
The \emph{stack trace} therefore shows us exactly where the error happened and from where the code causing the error was called.%
180+
The \pgls{stackTrace} therefore shows us exactly where the error happened and from where the code causing the error was called.%
181181
%
182182
\begin{sloppypar}%
183-
After the stack trace, we can see information about the error printed that we passed in:
183+
After the \pgls{stackTrace}, we can see information about the error printed that we passed in:
184184
\textil{ArithmeticError: sqrt(inf) is not permitted.}
185185
We made this message by ourselves using an \pgls{fstring} when raising the \pythonilIdx{Exception}.
186186
We did this so that it tells the user that \pythonil{sqrt} was called with the argument \pythonil{inf} that we did not permit.%
187187
\end{sloppypar}%
188188
%
189189
The above information allows us to pretty much identify the source of the problem.
190-
It shall be stated here that new programmers often ignore the stack trace.
190+
It shall be stated here that new programmers often ignore the \pgls{stackTrace}.
191191
They see that a program produces and error and then try to figure out why by looking at their code.
192-
They often do not read the stack trace or the error information below it.%
192+
They often do not read the \pgls{stackTrace} or the error information below it.%
193193
%
194194
\bestPractice{exceptionStackTrace}{%
195-
The stack trace and error information printed on the \python\ console in case of an uncaught \pythonilIdx{Exception} are essential information to identify the problem. %
195+
The \pgls{stackTrace} and error information printed on the \python\ console in case of an uncaught \pythonilIdx{Exception} are essential information to identify the problem. %
196196
They should \emph{always} be read and understood before trying to improve the code.%
197197
}%
198198
%
@@ -204,7 +204,7 @@
204204
Terminating the process may seem rash, but it is not.
205205
If a programmer used our \pythonil{sqrt} function incorrectly, then this will force them to fix their error.
206206
If the input \pythonil{inf} was the result of corrupted data, another erroneous computation, or an input mistake by the user, then terminating the program prevented this error from propagating.
207-
For both scenarios, the stack trace and error output gives clear information about what went wrong and where.%
207+
For both scenarios, the \pgls{stackTrace} and error output gives clear information about what went wrong and where.%
208208
%
209209
\endhsection%
210210
%
@@ -296,7 +296,7 @@
296296
Trying to access it will \pythonilIdx{raise} a \pythonilIdx{NameError}.
297297
While we did declare it, the \python\ interpreter does not know this variable yet, as it does not have a value.
298298
Our program will terminate, because the \pythonilIdx{NameError} is never caught anywhere.
299-
Instead, the stack trace and error information will be printed in \cref{exec:exceptions:try_multi_except}.%
299+
Instead, the \pgls{stackTrace} and error information will be printed in \cref{exec:exceptions:try_multi_except}.%
300300
%
301301
\bestPractice{noAssignAfterRaise}{%
302302
If an \pythonilIdx{Exception} is raised, be aware that the control flow will immediately leave the current block. %

0 commit comments

Comments
 (0)