Skip to content

Commit 667ac5c

Browse files
committed
adding try catch fail
1 parent 100a0c2 commit 667ac5c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

figures/try-catch-fail.pdf

69 KB
Binary file not shown.

figures/try-catch-fail.svg

Lines changed: 3 additions & 0 deletions
Loading

promises.tex

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,22 @@ \section{Promises}\label{s:promises-promises}
326326
327327
\noindent
328328
then the error message won't appear
329-
because the function \texttt{fetch} is asynchronous.
329+
because the function \texttt{fetch} is asynchronous,
330+
which means that code executes in this order:
331+
332+
\begin{enumerate}
333+
\item
334+
inside try, ask the computer to execute \texttt{fetch(url)} at some point in the future
335+
\item
336+
since asking this doesn't cause an exception, skip the catch
337+
\item
338+
then run \texttt{fetch(url)},
339+
which fails without anything in place to catch the exception
340+
because the \texttt{try...catch} has already finished
341+
so \texttt{console.log} never runs and the error message doesn't appear.
342+
\end{enumerate}
343+
344+
\figpdf{figures/try-catch-fail.pdf}{When Try...Catch Fails}{f:try-catch-fail}
330345
331346
There are two passes of execution in this block:
332347
The first is the \texttt{try...catch} event loop,

0 commit comments

Comments
 (0)