Skip to content

Commit bc793ff

Browse files
committed
Website build
1 parent 20e54b3 commit bc793ff

File tree

3 files changed

+168
-15
lines changed

3 files changed

+168
-15
lines changed

6_exceptions.html

Lines changed: 84 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,20 @@
6161

6262
<div class="section" id="errors-and-exceptions">
6363
<span id="id1"></span><h1><span class="section-number">6. </span>Errors and exceptions<a class="headerlink" href="#errors-and-exceptions" title="Permalink to this headline"></a></h1>
64-
<p>It is a sight familiar to every programmer: instead of producing the
64+
<details class="sphinx-bs dropdown card mb-3">
65+
<summary class="summary-title card-header">
66+
Video: errors and exceptions.<div class="summary-down docutils">
67+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
68+
<div class="summary-up docutils">
69+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
70+
</summary><div class="summary-content card-body docutils">
71+
<div class="vimeo docutils container">
72+
<iframe src="https://player.vimeo.com/video/509280820"
73+
frameborder="0" allow="autoplay; fullscreen"
74+
allowfullscreen></iframe></div>
75+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=d58d4c55-6216-4deb-be70-acc7015033f4">watch this video on Panopto</a>.</p>
76+
</div>
77+
</details><p>It is a sight familiar to every programmer: instead of producing the
6578
desired result, the screen is filled with seemingly unintelligible
6679
garbage because an error has occurred. Producing errors is an
6780
unavoidable part of programming, so learning to understand and correct
@@ -204,7 +217,20 @@ <h2><span class="section-number">6.2. </span>Exceptions<a class="headerlink" hre
204217
</div>
205218
<div class="section" id="tracebacks-finding-errors">
206219
<h2><span class="section-number">6.3. </span>Tracebacks: finding errors<a class="headerlink" href="#tracebacks-finding-errors" title="Permalink to this headline"></a></h2>
207-
<p>The errors we have looked at so far have all been located in the top
220+
<details class="sphinx-bs dropdown card mb-3">
221+
<summary class="summary-title card-header">
222+
Video: tracebacks.<div class="summary-down docutils">
223+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
224+
<div class="summary-up docutils">
225+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
226+
</summary><div class="summary-content card-body docutils">
227+
<div class="vimeo docutils container">
228+
<iframe src="https://player.vimeo.com/video/509280880"
229+
frameborder="0" allow="autoplay; fullscreen"
230+
allowfullscreen></iframe></div>
231+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=f3f8a555-31c8-41e3-a176-acc701503469">watch this video on Panopto</a>.</p>
232+
</div>
233+
</details><p>The errors we have looked at so far have all been located in the top
208234
level of code either typed directly into iPython or executed in a
209235
script. However, what happens if an error occurs in a function call or
210236
even several functions down? Consider the following code, which uses
@@ -256,7 +282,20 @@ <h2><span class="section-number">6.3. </span>Tracebacks: finding errors<a class=
256282
the call stack.</p>
257283
<div class="section" id="the-call-stack">
258284
<h3><span class="section-number">6.3.1. </span>The call stack<a class="headerlink" href="#the-call-stack" title="Permalink to this headline"></a></h3>
259-
<p>A Python program is a sequence of Python statements, which are
285+
<details class="sphinx-bs dropdown card mb-3">
286+
<summary class="summary-title card-header">
287+
Video: the call stack.<div class="summary-down docutils">
288+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
289+
<div class="summary-up docutils">
290+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
291+
</summary><div class="summary-content card-body docutils">
292+
<div class="vimeo docutils container">
293+
<iframe src="https://player.vimeo.com/video/509281576"
294+
frameborder="0" allow="autoplay; fullscreen"
295+
allowfullscreen></iframe></div>
296+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=cab860f1-ff35-4402-afe9-acc701503419">watch this video on Panopto</a>.</p>
297+
</div>
298+
</details><p>A Python program is a sequence of Python statements, which are
260299
executed in a sequence determined by the flow control logic of the
261300
program itself. Each statement contains zero or more function calls <a class="footnote-reference brackets" href="#function" id="id2">1</a>,
262301
which are executed in the course of evaluating that statement.</p>
@@ -287,10 +326,6 @@ <h3><span class="section-number">6.3.1. </span>The call stack<a class="headerlin
287326
functions which call functions and so on in a nearly limitless
288327
sequence, there can be a number of stack frames in existence at any
289328
time.</p>
290-
<div class="admonition note">
291-
<p class="admonition-title">Note</p>
292-
<p>FIXME: Do a video using the XCode debugger to show the call stack.</p>
293-
</div>
294329
</div>
295330
<div class="section" id="interpreting-tracebacks">
296331
<h3><span class="section-number">6.3.2. </span>Interpreting tracebacks<a class="headerlink" href="#interpreting-tracebacks" title="Permalink to this headline"></a></h3>
@@ -359,7 +394,20 @@ <h3><span class="section-number">6.3.2. </span>Interpreting tracebacks<a class="
359394
</div>
360395
<div class="section" id="raising-exceptions">
361396
<span id="id3"></span><h2><span class="section-number">6.4. </span>Raising exceptions<a class="headerlink" href="#raising-exceptions" title="Permalink to this headline"></a></h2>
362-
<p>Thus far we’ve noticed that an exception occurs when something goes
397+
<details class="sphinx-bs dropdown card mb-3">
398+
<summary class="summary-title card-header">
399+
Video: raising an exception.<div class="summary-down docutils">
400+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
401+
<div class="summary-up docutils">
402+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
403+
</summary><div class="summary-content card-body docutils">
404+
<div class="vimeo docutils container">
405+
<iframe src="https://player.vimeo.com/video/509492490"
406+
frameborder="0" allow="autoplay; fullscreen"
407+
allowfullscreen></iframe></div>
408+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=d0b05710-bbb8-47b4-9afa-acc8011e7635">watch this video on Panopto</a>.</p>
409+
</div>
410+
</details><p>Thus far we’ve noticed that an exception occurs when something goes
363411
wrong in a program, and that the <a class="reference internal" href="2_programs_in_files.html#term-Python-interpreter"><span class="xref std std-term">Python interpreter</span></a> will stop
364412
at that point and print out a <a class="reference internal" href="#term-traceback"><span class="xref std std-term">traceback</span></a>. We’ll now examine the
365413
process by which an exception occurs.</p>
@@ -459,7 +507,20 @@ <h3><span class="section-number">6.3.2. </span>Interpreting tracebacks<a class="
459507
</div>
460508
<div class="section" id="handling-exceptions">
461509
<span id="id4"></span><h2><span class="section-number">6.5. </span>Handling exceptions<a class="headerlink" href="#handling-exceptions" title="Permalink to this headline"></a></h2>
462-
<p>So far we have seen several different sorts of exception, how to raise
510+
<details class="sphinx-bs dropdown card mb-3">
511+
<summary class="summary-title card-header">
512+
Video: handling exceptions.<div class="summary-down docutils">
513+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
514+
<div class="summary-up docutils">
515+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
516+
</summary><div class="summary-content card-body docutils">
517+
<div class="vimeo docutils container">
518+
<iframe src="https://player.vimeo.com/video/509492495"
519+
frameborder="0" allow="autoplay; fullscreen"
520+
allowfullscreen></iframe></div>
521+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=25f14034-34a1-44ec-83f7-acc8011e76a0">watch this video on Panopto</a>.</p>
522+
</div>
523+
</details><p>So far we have seen several different sorts of exception, how to raise
463524
them, and how to understand the resulting <a class="reference internal" href="#term-traceback"><span class="xref std std-term">traceback</span></a>. The
464525
<a class="reference internal" href="#term-traceback"><span class="xref std std-term">traceback</span></a> is very helpful if the exception was caused by a bug
465526
in our code, so that we need to understand and correct the
@@ -542,7 +603,20 @@ <h3><span class="section-number">6.3.2. </span>Interpreting tracebacks<a class="
542603
</div>
543604
<div class="section" id="except-clauses">
544605
<h3><span class="section-number">6.5.1. </span>Except clauses<a class="headerlink" href="#except-clauses" title="Permalink to this headline"></a></h3>
545-
<p>Let’s look in a little more detail at how <a class="reference external" href="https://docs.python.org/3/reference/compound_stmts.html#except" title="(in Python v3.9)"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> works. The full
606+
<details class="sphinx-bs dropdown card mb-3">
607+
<summary class="summary-title card-header">
608+
Video: further exception handling.<div class="summary-down docutils">
609+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
610+
<div class="summary-up docutils">
611+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
612+
</summary><div class="summary-content card-body docutils">
613+
<div class="vimeo docutils container">
614+
<iframe src="https://player.vimeo.com/video/509492496"
615+
frameborder="0" allow="autoplay; fullscreen"
616+
allowfullscreen></iframe></div>
617+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=0d7840de-17b2-4268-b079-acc8011e7660">watch this video on Panopto</a>.</p>
618+
</div>
619+
</details><p>Let’s look in a little more detail at how <a class="reference external" href="https://docs.python.org/3/reference/compound_stmts.html#except" title="(in Python v3.9)"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> works. The full
546620
version of the except statement takes a tuple of exception classes. If an
547621
exception is raised matching any of the exceptions in that tuple then the code
548622
in the except block is executed.</p>

_sources/6_exceptions.rst.txt

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
Errors and exceptions
44
=====================
55

6+
.. dropdown:: Video: errors and exceptions.
7+
8+
.. container:: vimeo
9+
10+
.. raw:: html
11+
12+
<iframe src="https://player.vimeo.com/video/509280820"
13+
frameborder="0" allow="autoplay; fullscreen"
14+
allowfullscreen></iframe>
15+
16+
Imperial students can also `watch this video on Panopto
17+
<https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=d58d4c55-6216-4deb-be70-acc7015033f4>`__.
18+
19+
20+
621
It is a sight familiar to every programmer: instead of producing the
722
desired result, the screen is filled with seemingly unintelligible
823
garbage because an error has occurred. Producing errors is an
@@ -166,6 +181,20 @@ exceptions so there are many more defined in third-party packages.
166181
Tracebacks: finding errors
167182
--------------------------
168183

184+
.. dropdown:: Video: tracebacks.
185+
186+
.. container:: vimeo
187+
188+
.. raw:: html
189+
190+
<iframe src="https://player.vimeo.com/video/509280880"
191+
frameborder="0" allow="autoplay; fullscreen"
192+
allowfullscreen></iframe>
193+
194+
Imperial students can also `watch this video on Panopto
195+
<https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=f3f8a555-31c8-41e3-a176-acc701503469>`__.
196+
197+
169198
The errors we have looked at so far have all been located in the top
170199
level of code either typed directly into iPython or executed in a
171200
script. However, what happens if an error occurs in a function call or
@@ -224,6 +253,19 @@ the call stack.
224253
The call stack
225254
..............
226255

256+
.. dropdown:: Video: the call stack.
257+
258+
.. container:: vimeo
259+
260+
.. raw:: html
261+
262+
<iframe src="https://player.vimeo.com/video/509281576"
263+
frameborder="0" allow="autoplay; fullscreen"
264+
allowfullscreen></iframe>
265+
266+
Imperial students can also `watch this video on Panopto
267+
<https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=cab860f1-ff35-4402-afe9-acc701503419>`__.
268+
227269
A Python program is a sequence of Python statements, which are
228270
executed in a sequence determined by the flow control logic of the
229271
program itself. Each statement contains zero or more function calls [#function]_,
@@ -258,10 +300,6 @@ functions which call functions and so on in a nearly limitless
258300
sequence, there can be a number of stack frames in existence at any
259301
time.
260302

261-
.. note::
262-
263-
FIXME: Do a video using the XCode debugger to show the call stack.
264-
265303
Interpreting tracebacks
266304
.......................
267305

@@ -338,6 +376,20 @@ line of the iPython session.
338376
Raising exceptions
339377
------------------
340378

379+
.. dropdown:: Video: raising an exception.
380+
381+
.. container:: vimeo
382+
383+
.. raw:: html
384+
385+
<iframe src="https://player.vimeo.com/video/509492490"
386+
frameborder="0" allow="autoplay; fullscreen"
387+
allowfullscreen></iframe>
388+
389+
Imperial students can also `watch this video on Panopto
390+
<https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=d0b05710-bbb8-47b4-9afa-acc8011e7635>`__.
391+
392+
341393
Thus far we've noticed that an exception occurs when something goes
342394
wrong in a program, and that the :term:`Python interpreter` will stop
343395
at that point and print out a :term:`traceback`. We'll now examine the
@@ -442,6 +494,20 @@ distinction is of negligible importance for our current purposes.
442494
Handling exceptions
443495
-------------------
444496

497+
.. dropdown:: Video: handling exceptions.
498+
499+
.. container:: vimeo
500+
501+
.. raw:: html
502+
503+
<iframe src="https://player.vimeo.com/video/509492495"
504+
frameborder="0" allow="autoplay; fullscreen"
505+
allowfullscreen></iframe>
506+
507+
Imperial students can also `watch this video on Panopto
508+
<https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=25f14034-34a1-44ec-83f7-acc8011e76a0>`__.
509+
510+
445511
So far we have seen several different sorts of exception, how to raise
446512
them, and how to understand the resulting :term:`traceback`. The
447513
:term:`traceback` is very helpful if the exception was caused by a bug
@@ -533,6 +599,19 @@ version of :func:`gcd` then we have, as we might expect:
533599
Except clauses
534600
..............
535601

602+
.. dropdown:: Video: further exception handling.
603+
604+
.. container:: vimeo
605+
606+
.. raw:: html
607+
608+
<iframe src="https://player.vimeo.com/video/509492496"
609+
frameborder="0" allow="autoplay; fullscreen"
610+
allowfullscreen></iframe>
611+
612+
Imperial students can also `watch this video on Panopto
613+
<https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=0d7840de-17b2-4268-b079-acc8011e7660>`__.
614+
536615
Let's look in a little more detail at how :keyword:`except` works. The full
537616
version of the except statement takes a tuple of exception classes. If an
538617
exception is raised matching any of the exceptions in that tuple then the code

0 commit comments

Comments
 (0)