File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -326,7 +326,22 @@ \section{Promises}\label{s:promises-promises}
326
326
327
327
\noindent
328
328
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}
330
345
331
346
There are two passes of execution in this block:
332
347
The first is the \texttt {try...catch} event loop,
You can’t perform that action at this time.
0 commit comments