File: exceptions.html

package info (click to toggle)
python-apsw 3.46.0.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,684 kB
  • sloc: python: 13,125; ansic: 12,334; javascript: 911; makefile: 10; sh: 7
file content (676 lines) | stat: -rw-r--r-- 61,919 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="./">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Exceptions and Errors &mdash; APSW 3.46.0.1 documentation</title>
      <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=72bcf2f2" />
      <link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=19f00094" />
      <link rel="stylesheet" type="text/css" href="_static/apsw.css?v=3c7e2631" />

  
    <link rel="shortcut icon" href="_static/favicon.ico"/>
  <!--[if lt IE 9]>
    <script src="_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="_static/jquery.js?v=5d32c60e"></script>
        <script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
        <script src="_static/documentation_options.js?v=d98f5d2b"></script>
        <script src="_static/doctools.js?v=9a2dae69"></script>
        <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="_static/js/theme.js"></script>
    <link rel="author" title="About these documents" href="about.html" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="copyright" title="Copyright" href="copyright.html" />
    <link rel="next" title="Execution and tracing" href="execution.html" />
    <link rel="prev" title="Various interesting and useful bits of functionality" href="ext.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="index.html" class="icon icon-home">
            APSW
              <img src="_static/apswlogo.png" class="logo" alt="Logo"/>
          </a>
              <div class="version">
                3.46.0.1
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="about.html">About</a></li>
<li class="toctree-l1"><a class="reference internal" href="tips.html">Tips</a></li>
<li class="toctree-l1"><a class="reference internal" href="example.html">Example/Tour</a></li>
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation and customization</a></li>
<li class="toctree-l1"><a class="reference internal" href="extensions.html">Extensions</a></li>
<li class="toctree-l1"><a class="reference internal" href="apsw.html">APSW Module</a></li>
<li class="toctree-l1"><a class="reference internal" href="connection.html">Connections to a database</a></li>
<li class="toctree-l1"><a class="reference internal" href="cursor.html">Cursors (executing SQL)</a></li>
<li class="toctree-l1"><a class="reference internal" href="blob.html">Blob Input/Output</a></li>
<li class="toctree-l1"><a class="reference internal" href="backup.html">Backup</a></li>
<li class="toctree-l1"><a class="reference internal" href="vtable.html">Virtual Tables</a></li>
<li class="toctree-l1"><a class="reference internal" href="vfs.html">Virtual File System (VFS)</a></li>
<li class="toctree-l1"><a class="reference internal" href="shell.html">Shell</a></li>
<li class="toctree-l1"><a class="reference internal" href="bestpractice.html">Best Practice</a></li>
<li class="toctree-l1"><a class="reference internal" href="ext.html">Various interesting and useful bits of functionality</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Exceptions and Errors</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#chaining">Chaining</a></li>
<li class="toctree-l2"><a class="reference internal" href="#unraisable">Unraisable</a></li>
<li class="toctree-l2"><a class="reference internal" href="#exception-classes">Exception Classes</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#apsw.Error"><code class="docutils literal notranslate"><span class="pre">Error</span></code></a><ul>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Error.result"><code class="docutils literal notranslate"><span class="pre">Error.result</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Error.extendedresult"><code class="docutils literal notranslate"><span class="pre">Error.extendedresult</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.Error.error_offset"><code class="docutils literal notranslate"><span class="pre">Error.error_offset</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#apsw-specific-exceptions">APSW specific exceptions</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#apsw.ThreadingViolationError"><code class="docutils literal notranslate"><span class="pre">ThreadingViolationError</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.ForkingViolationError"><code class="docutils literal notranslate"><span class="pre">ForkingViolationError</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.IncompleteExecutionError"><code class="docutils literal notranslate"><span class="pre">IncompleteExecutionError</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.ConnectionNotClosedError"><code class="docutils literal notranslate"><span class="pre">ConnectionNotClosedError</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.ConnectionClosedError"><code class="docutils literal notranslate"><span class="pre">ConnectionClosedError</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.CursorClosedError"><code class="docutils literal notranslate"><span class="pre">CursorClosedError</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.BindingsError"><code class="docutils literal notranslate"><span class="pre">BindingsError</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.ExecutionCompleteError"><code class="docutils literal notranslate"><span class="pre">ExecutionCompleteError</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.ExecTraceAbort"><code class="docutils literal notranslate"><span class="pre">ExecTraceAbort</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.ExtensionLoadingError"><code class="docutils literal notranslate"><span class="pre">ExtensionLoadingError</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VFSNotImplementedError"><code class="docutils literal notranslate"><span class="pre">VFSNotImplementedError</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apsw.VFSFileClosedError"><code class="docutils literal notranslate"><span class="pre">VFSFileClosedError</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#sqlite-exceptions">SQLite Exceptions</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#general-errors">General Errors</a></li>
<li class="toctree-l4"><a class="reference internal" href="#internal-errors">Internal Errors</a></li>
<li class="toctree-l4"><a class="reference internal" href="#permissions-etc">Permissions Etc</a></li>
<li class="toctree-l4"><a class="reference internal" href="#abort-busy-etc">Abort/Busy Etc</a></li>
<li class="toctree-l4"><a class="reference internal" href="#memory-disk">Memory/Disk</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#augmented-stack-traces">Augmented stack traces</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="execution.html">Execution and tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="dbapi.html">DBAPI notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="pysqlite.html">sqlite3 module differences</a></li>
<li class="toctree-l1"><a class="reference internal" href="benchmarking.html">Benchmarking</a></li>
<li class="toctree-l1"><a class="reference internal" href="copyright.html">Copyright and License</a></li>
<li class="toctree-l1"><a class="reference internal" href="changes.html">Change History</a></li>
<li class="toctree-l1"><a class="reference internal" href="py-modindex.html">Module Index</a></li>
<li class="toctree-l1"><a class="reference internal" href="genindex.html">Index</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">APSW</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content style-external-links">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
      <li class="breadcrumb-item active">Exceptions and Errors</li>
      <li class="wy-breadcrumbs-aside">
            <a href="_sources/exceptions.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul><div class="rst-breadcrumbs-buttons" role="navigation" aria-label="Sequential page navigation">
        <a href="ext.html" class="btn btn-neutral float-left" title="Various interesting and useful bits of functionality" accesskey="p"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="execution.html" class="btn btn-neutral float-right" title="Execution and tracing" accesskey="n">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
  </div>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="exceptions-and-errors">
<span id="exceptions"></span><h1>Exceptions and Errors<a class="headerlink" href="#exceptions-and-errors" title="Link to this heading"></a></h1>
<p>Python uses <a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.12)"><code class="xref py py-class docutils literal notranslate"><span class="pre">exceptions</span></code></a> to indicate an error has
happened.  The SQLite library uses <a class="reference external" href="https://www.sqlite.org/rescode.html">integer error codes</a>.  APSW maps between the two
systems as needed.  Exceptions raised in Python code called by SQLite
will have that exception present when control returns to Python, and
SQLite will understand that an error occurred.</p>
<section id="chaining">
<h2>Chaining<a class="headerlink" href="#chaining" title="Link to this heading"></a></h2>
<p>When an error is reported to SQLite, it may take further actions.  For
example errors in <a class="reference internal" href="vfs.html"><span class="doc">VFS</span></a> can result in error recovery
attempts, while an error in a window function step method will result
in the final method being called to do clean up.  Your code
implementing those could also have additional exceptions.</p>
<p>When multiple exceptions occur in the same SQLite control flow then
they will be <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-3134/"><strong>chained</strong></a>.  Python’s traceback printing code
will show <a class="reference external" href="https://docs.python.org/3/library/exceptions.html#exception-context">all the exceptions</a>.</p>
</section>
<section id="unraisable">
<span id="id1"></span><h2>Unraisable<a class="headerlink" href="#unraisable" title="Link to this heading"></a></h2>
<p>There are a few places where it is not possible for a Python exception
to be reported to SQLite as an error, and Python C code does not allow
destructors to report exceptions.  These exceptions are reported via
<a class="reference external" href="https://docs.python.org/3/library/sys.html#sys.unraisablehook">sys.unraisablehook</a>,
and if that is not present then <a class="reference external" href="https://docs.python.org/3/library/sys.html#sys.excepthook">sys.excepthook</a>.</p>
<p><a class="reference external" href="https://www.sqlite.org/c3ref/log.html">sqlite3_log</a> is also called
so that you will have the context of when the exception happened
relative to the errors SQLite is logging.</p>
</section>
<section id="exception-classes">
<h2>Exception Classes<a class="headerlink" href="#exception-classes" title="Link to this heading"></a></h2>
<dl class="py exception">
<dt class="sig sig-object py" id="apsw.Error">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">Error</span></span><a class="headerlink" href="#apsw.Error" title="Link to this definition"></a></dt>
<dd><p>This is the base for APSW exceptions.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.Error.result">
<span class="sig-prename descclassname"><span class="pre">Error.</span></span><span class="sig-name descname"><span class="pre">result</span></span><a class="headerlink" href="#apsw.Error.result" title="Link to this definition"></a></dt>
<dd><p>For exceptions corresponding to <a class="reference external" href="https://sqlite.org/c3ref/c_abort.html">SQLite error codes</a> codes this attribute
is the numeric error code.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.Error.extendedresult">
<span class="sig-prename descclassname"><span class="pre">Error.</span></span><span class="sig-name descname"><span class="pre">extendedresult</span></span><a class="headerlink" href="#apsw.Error.extendedresult" title="Link to this definition"></a></dt>
<dd><p>APSW runs with <a class="reference external" href="https://sqlite.org/rescode.html">extended result codes</a> turned on.
This attribute includes the detailed code.</p>
<p>As an example, if SQLite issued a read request and the system
returned less data than expected then <a class="reference internal" href="#apsw.Error.result" title="apsw.Error.result"><code class="xref py py-attr docutils literal notranslate"><span class="pre">result</span></code></a>
would have the value <em>SQLITE_IOERR</em> while
<a class="reference internal" href="#apsw.Error.extendedresult" title="apsw.Error.extendedresult"><code class="xref py py-attr docutils literal notranslate"><span class="pre">extendedresult</span></code></a> would have the value
<em>SQLITE_IOERR_SHORT_READ</em>.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="apsw.Error.error_offset">
<span class="sig-prename descclassname"><span class="pre">Error.</span></span><span class="sig-name descname"><span class="pre">error_offset</span></span><a class="headerlink" href="#apsw.Error.error_offset" title="Link to this definition"></a></dt>
<dd><p>The location of the error in the SQL when encoded in UTF-8.
The value is from <a class="reference external" href="https://www.sqlite.org/c3ref/errcode.html">sqlite3_error_offset</a>, and will be
<cite>-1</cite> when a specific token in the input is not the cause.</p>
</dd></dl>

<section id="apsw-specific-exceptions">
<h3>APSW specific exceptions<a class="headerlink" href="#apsw-specific-exceptions" title="Link to this heading"></a></h3>
<p>The following exceptions happen when APSW detects various problems.</p>
<dl class="py exception">
<dt class="sig sig-object py" id="apsw.ThreadingViolationError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">ThreadingViolationError</span></span><a class="headerlink" href="#apsw.ThreadingViolationError" title="Link to this definition"></a></dt>
<dd><p>You have used an object concurrently in two threads. For example you
may try to use the same cursor in two different threads at the same
time, or tried to close the same connection in two threads at the
same time.</p>
<p>You can also get this exception by using a cursor as an argument to
itself (eg as the input data for <a class="reference internal" href="cursor.html#apsw.Cursor.executemany" title="apsw.Cursor.executemany"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cursor.executemany()</span></code></a>).
Cursors can only be used for one thing at a time.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.ForkingViolationError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">ForkingViolationError</span></span><a class="headerlink" href="#apsw.ForkingViolationError" title="Link to this definition"></a></dt>
<dd><p>See <a class="reference internal" href="apsw.html#apsw.fork_checker" title="apsw.fork_checker"><code class="xref py py-meth docutils literal notranslate"><span class="pre">apsw.fork_checker()</span></code></a>.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.IncompleteExecutionError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">IncompleteExecutionError</span></span><a class="headerlink" href="#apsw.IncompleteExecutionError" title="Link to this definition"></a></dt>
<dd><p>You have tried to start a new SQL execute call before executing all
the previous ones. See the <a class="reference internal" href="execution.html#executionmodel"><span class="std std-ref">execution model</span></a>
for more details.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.ConnectionNotClosedError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">ConnectionNotClosedError</span></span><a class="headerlink" href="#apsw.ConnectionNotClosedError" title="Link to this definition"></a></dt>
<dd><p>This exception is no longer generated.  It was required in earlier
releases due to constraints in threading usage with SQLite.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.ConnectionClosedError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">ConnectionClosedError</span></span><a class="headerlink" href="#apsw.ConnectionClosedError" title="Link to this definition"></a></dt>
<dd><p>You have called <a class="reference internal" href="connection.html#apsw.Connection.close" title="apsw.Connection.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.close()</span></code></a> and then continued to use
the <a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Connection</span></code></a> or associated <a class="reference internal" href="cursor.html#apsw.Cursor" title="apsw.Cursor"><code class="xref py py-class docutils literal notranslate"><span class="pre">cursors</span></code></a>.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.CursorClosedError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">CursorClosedError</span></span><a class="headerlink" href="#apsw.CursorClosedError" title="Link to this definition"></a></dt>
<dd><p>You have called <a class="reference internal" href="cursor.html#apsw.Cursor.close" title="apsw.Cursor.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cursor.close()</span></code></a> and then tried to use the cursor.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.BindingsError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">BindingsError</span></span><a class="headerlink" href="#apsw.BindingsError" title="Link to this definition"></a></dt>
<dd><p>There are several causes for this exception.  When using tuples, an incorrect number of bindings where supplied:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;select ?,?,?&quot;</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>     <span class="c1"># too few bindings</span>
<span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;select ?,?,?&quot;</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span> <span class="c1"># too many bindings</span>
</pre></div>
</div>
<p>You are using named bindings, but not all bindings are named.  You should either use entirely the
named style or entirely numeric (unnamed) style:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;select * from foo where x=:name and y=?&quot;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.ExecutionCompleteError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">ExecutionCompleteError</span></span><a class="headerlink" href="#apsw.ExecutionCompleteError" title="Link to this definition"></a></dt>
<dd><p>Execution of the statements is complete and cannot be run further.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.ExecTraceAbort">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">ExecTraceAbort</span></span><a class="headerlink" href="#apsw.ExecTraceAbort" title="Link to this definition"></a></dt>
<dd><p>The <a class="reference internal" href="execution.html#executiontracer"><span class="std std-ref">execution tracer</span></a> returned False so
execution was aborted.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.ExtensionLoadingError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">ExtensionLoadingError</span></span><a class="headerlink" href="#apsw.ExtensionLoadingError" title="Link to this definition"></a></dt>
<dd><p>An error happened loading an <a class="reference external" href="https://sqlite.org/loadext.html">extension</a>.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.VFSNotImplementedError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">VFSNotImplementedError</span></span><a class="headerlink" href="#apsw.VFSNotImplementedError" title="Link to this definition"></a></dt>
<dd><p>A call cannot be made to an inherited <a class="reference internal" href="vfs.html#vfs"><span class="std std-ref">Virtual File System (VFS)</span></a> method as the VFS
does not implement the method.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.VFSFileClosedError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">VFSFileClosedError</span></span><a class="headerlink" href="#apsw.VFSFileClosedError" title="Link to this definition"></a></dt>
<dd><p>The VFS file is closed so the operation cannot be performed.</p>
</dd></dl>

</section>
<section id="sqlite-exceptions">
<h3>SQLite Exceptions<a class="headerlink" href="#sqlite-exceptions" title="Link to this heading"></a></h3>
<p>The following lists which Exception classes correspond to which <a class="reference external" href="https://sqlite.org/c3ref/c_abort.html">SQLite
error codes</a>.</p>
<section id="general-errors">
<h4>General Errors<a class="headerlink" href="#general-errors" title="Link to this heading"></a></h4>
<dl class="py exception">
<dt class="sig sig-object py" id="apsw.SQLError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">SQLError</span></span><a class="headerlink" href="#apsw.SQLError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#error">SQLITE_ERROR</a>.  The
standard error code, unless a more specific one is  applicable.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.MismatchError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">MismatchError</span></span><a class="headerlink" href="#apsw.MismatchError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#mismatch">SQLITE_MISMATCH</a>. Data
type mismatch.  For example a rowid or integer primary key must be
an integer.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.NotFoundError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">NotFoundError</span></span><a class="headerlink" href="#apsw.NotFoundError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#notfound">SQLITE_NOTFOUND</a>.
Returned when various internal items were not found such as requests
for non-existent system calls or file controls.</p>
</dd></dl>

</section>
<section id="internal-errors">
<h4>Internal Errors<a class="headerlink" href="#internal-errors" title="Link to this heading"></a></h4>
<dl class="py exception">
<dt class="sig sig-object py" id="apsw.InternalError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">InternalError</span></span><a class="headerlink" href="#apsw.InternalError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#internal">SQLITE_INTERNAL</a>. (No
longer used) Internal logic error in SQLite.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.ProtocolError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">ProtocolError</span></span><a class="headerlink" href="#apsw.ProtocolError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#protocol">SQLITE_PROTOCOL</a>. (No
longer used) Database lock protocol error.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.MisuseError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">MisuseError</span></span><a class="headerlink" href="#apsw.MisuseError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#misuse">SQLITE_MISUSE</a>.  SQLite
library used incorrectly - typically similar to <em>ValueError</em> in
Python.  Examples include not having enough flags when opening a
connection (eg not including a READ or WRITE flag), or out of spec
such as registering a function with more than 127 parameters.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.RangeError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">RangeError</span></span><a class="headerlink" href="#apsw.RangeError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#range">SQLITE_RANGE</a>.  (Cannot
be generated using APSW).  2nd parameter to <a class="reference external" href="https://sqlite.org/c3ref/bind_blob.html">sqlite3_bind</a> out of range</p>
</dd></dl>

</section>
<section id="permissions-etc">
<h4>Permissions Etc<a class="headerlink" href="#permissions-etc" title="Link to this heading"></a></h4>
<dl class="py exception">
<dt class="sig sig-object py" id="apsw.PermissionsError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">PermissionsError</span></span><a class="headerlink" href="#apsw.PermissionsError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#perm">SQLITE_PERM</a>. Access
permission denied by the operating system.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.ReadOnlyError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">ReadOnlyError</span></span><a class="headerlink" href="#apsw.ReadOnlyError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#readonly">SQLITE_READONLY</a>.
Attempt to write to a readonly database.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.CantOpenError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">CantOpenError</span></span><a class="headerlink" href="#apsw.CantOpenError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#cantopen">SQLITE_CANTOPEN</a>.
Unable to open the database file.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.AuthError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">AuthError</span></span><a class="headerlink" href="#apsw.AuthError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#auth">SQLITE_AUTH</a>.
<a class="reference internal" href="connection.html#apsw.Connection.authorizer" title="apsw.Connection.authorizer"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Authorization</span></code></a> denied.</p>
</dd></dl>

</section>
<section id="abort-busy-etc">
<h4>Abort/Busy Etc<a class="headerlink" href="#abort-busy-etc" title="Link to this heading"></a></h4>
<dl class="py exception">
<dt class="sig sig-object py" id="apsw.AbortError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">AbortError</span></span><a class="headerlink" href="#apsw.AbortError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#abort">SQLITE_ABORT</a>. Callback
routine requested an abort.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.BusyError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">BusyError</span></span><a class="headerlink" href="#apsw.BusyError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#busy">SQLITE_BUSY</a>.  The
database file is locked.  Use  <a class="reference internal" href="connection.html#apsw.Connection.set_busy_timeout" title="apsw.Connection.set_busy_timeout"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.set_busy_timeout()</span></code></a>
to change how long SQLite waits for the database to be unlocked or
<a class="reference internal" href="connection.html#apsw.Connection.set_busy_handler" title="apsw.Connection.set_busy_handler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.set_busy_handler()</span></code></a> to use your own handler.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.LockedError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">LockedError</span></span><a class="headerlink" href="#apsw.LockedError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#locked">SQLITE_LOCKED</a>.  Shared
cache lock.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.InterruptError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">InterruptError</span></span><a class="headerlink" href="#apsw.InterruptError" title="Link to this definition"></a></dt>
<dd><p>SQLITE_INTERRUPT &lt;<a class="reference external" href="https://sqlite.org/rescode.html#interrupt">https://sqlite.org/rescode.html#interrupt</a>&gt;`__.
Operation terminated by <a class="reference external" href="https://sqlite.org/c3ref/interrupt.html">sqlite3_interrupt</a> - use
<a class="reference internal" href="connection.html#apsw.Connection.interrupt" title="apsw.Connection.interrupt"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.interrupt()</span></code></a>.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.SchemaChangeError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">SchemaChangeError</span></span><a class="headerlink" href="#apsw.SchemaChangeError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#schema">SQLITE_SCHEMA</a>.  The
database schema changed.  A  <a class="reference internal" href="cursor.html#apsw.Cursor.execute" title="apsw.Cursor.execute"><code class="xref py py-meth docutils literal notranslate"><span class="pre">prepared</span> <span class="pre">statement</span></code></a> becomes invalid if the database schema was
changed.  Behind the scenes SQLite reprepares the statement.
Another or the same <a class="reference internal" href="connection.html#apsw.Connection" title="apsw.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Connection</span></code></a> may change the schema again
before the statement runs.  SQLite will retry before giving up and
returning this error.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.ConstraintError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">ConstraintError</span></span><a class="headerlink" href="#apsw.ConstraintError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#constraint">SQLITE_CONSTRAINT</a>.
Abort due to <a class="reference external" href="https://sqlite.org/lang_createtable.html">constraint</a> violation.</p>
</dd></dl>

</section>
<section id="memory-disk">
<h4>Memory/Disk<a class="headerlink" href="#memory-disk" title="Link to this heading"></a></h4>
<dl class="py exception">
<dt class="sig sig-object py" id="apsw.NoMemError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">NoMemError</span></span><a class="headerlink" href="#apsw.NoMemError" title="Link to this definition"></a></dt>
<dd><dl class="simple">
<dt><a class="reference external" href="https://sqlite.org/rescode.html#nomem">SQLITE_NOMEM</a>.  A memory</dt><dd><p>allocation failed.</p>
</dd>
</dl>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.IOError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">IOError</span></span><a class="headerlink" href="#apsw.IOError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#ioerr">SQLITE_IOERR</a>.  A disk
I/O error occurred.  The <a class="reference internal" href="#exceptions"><span class="std std-ref">extended error code</span></a>
will give more detail.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.CorruptError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">CorruptError</span></span><a class="headerlink" href="#apsw.CorruptError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#corrupt">SQLITE_CORRUPT</a>.  The
database disk image appears to be a SQLite database but the values
inside are inconsistent.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.FullError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">FullError</span></span><a class="headerlink" href="#apsw.FullError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#full">SQLITE_FULL</a>.  The disk
appears to be full.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.TooBigError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">TooBigError</span></span><a class="headerlink" href="#apsw.TooBigError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#toobig">SQLITE_TOOBIG</a>.  String
or BLOB exceeds size limit.  You can  change the limits using
<a class="reference internal" href="connection.html#apsw.Connection.limit" title="apsw.Connection.limit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.limit()</span></code></a>.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.NoLFSError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">NoLFSError</span></span><a class="headerlink" href="#apsw.NoLFSError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#nolfs">SQLITE_NOLFS</a>.  SQLite
has attempted to use a feature not supported by the operating system
such as <a class="reference external" href="https://en.wikipedia.org/wiki/Large_file_support">large file support</a>.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.EmptyError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">EmptyError</span></span><a class="headerlink" href="#apsw.EmptyError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#empty">SQLITE_EMPTY</a>. Not
currently used.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.FormatError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">FormatError</span></span><a class="headerlink" href="#apsw.FormatError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#format">SQLITE_FORMAT</a>. (No
longer used) <a class="reference external" href="https://sqlite.org/lang_attach.html">Auxiliary database</a> format error.</p>
</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="apsw.NotADBError">
<em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">apsw.</span></span><span class="sig-name descname"><span class="pre">NotADBError</span></span><a class="headerlink" href="#apsw.NotADBError" title="Link to this definition"></a></dt>
<dd><p><a class="reference external" href="https://sqlite.org/rescode.html#notadb">SQLITE_NOTADB</a>.  File
opened that is not a database file.  SQLite has a header on database
files to verify they are indeed SQLite databases.</p>
</dd></dl>

</section>
</section>
<section id="augmented-stack-traces">
<span id="augmentedstacktraces"></span><h3>Augmented stack traces<a class="headerlink" href="#augmented-stack-traces" title="Link to this heading"></a></h3>
<p>When an exception occurs, Python does not include frames from
non-Python code (ie the C code called from Python).  This can make it
more difficult to work out what was going on when an exception
occurred for example when there are callbacks to collations, functions
or virtual tables, triggers firing etc.</p>
<p>This is an example showing the difference between the tracebacks you
would have got with earlier versions of apsw and the augmented
traceback:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">apsw</span>

<span class="k">def</span> <span class="nf">myfunc</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
  <span class="mi">1</span><span class="o">/</span><span class="mi">0</span>

<span class="n">con</span><span class="o">=</span><span class="n">apsw</span><span class="o">.</span><span class="n">Connection</span><span class="p">(</span><span class="s2">&quot;:memory:&quot;</span><span class="p">)</span>
<span class="n">con</span><span class="o">.</span><span class="n">create_scalar_function</span><span class="p">(</span><span class="s2">&quot;foo&quot;</span><span class="p">,</span> <span class="n">myfunc</span><span class="p">)</span>
<span class="n">con</span><span class="o">.</span><span class="n">create_scalar_function</span><span class="p">(</span><span class="s2">&quot;fam&quot;</span><span class="p">,</span> <span class="n">myfunc</span><span class="p">)</span>
<span class="n">cursor</span><span class="o">=</span><span class="n">con</span><span class="o">.</span><span class="n">cursor</span><span class="p">()</span>
<span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;create table bar(x,y,z);insert into bar values(1,2,3)&quot;</span><span class="p">)</span>
<span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;select foo(1) from bar&quot;</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Original Traceback</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
  <span class="n">File</span> <span class="s2">&quot;t.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">11</span><span class="p">,</span> <span class="ow">in</span> <span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span>
    <span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;select foo(1) from bar&quot;</span><span class="p">)</span>
  <span class="n">File</span> <span class="s2">&quot;t.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">4</span><span class="p">,</span> <span class="ow">in</span> <span class="n">myfunc</span>
    <span class="mi">1</span><span class="o">/</span><span class="mi">0</span>
<span class="ne">ZeroDivisionError</span><span class="p">:</span> <span class="n">integer</span> <span class="n">division</span> <span class="ow">or</span> <span class="n">modulo</span> <span class="n">by</span> <span class="n">zero</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Augmented Traceback</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
  <span class="n">File</span> <span class="s2">&quot;t.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">11</span><span class="p">,</span> <span class="ow">in</span> <span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span>
    <span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;select foo(1) from bar&quot;</span><span class="p">)</span>
  <span class="n">File</span> <span class="s2">&quot;apsw.c&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">3412</span><span class="p">,</span> <span class="ow">in</span> <span class="n">resetcursor</span>
  <span class="n">File</span> <span class="s2">&quot;apsw.c&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">1597</span><span class="p">,</span> <span class="ow">in</span> <span class="n">user</span><span class="o">-</span><span class="n">defined</span><span class="o">-</span><span class="n">scalar</span><span class="o">-</span><span class="n">foo</span>
  <span class="n">File</span> <span class="s2">&quot;t.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">4</span><span class="p">,</span> <span class="ow">in</span> <span class="n">myfunc</span>
    <span class="mi">1</span><span class="o">/</span><span class="mi">0</span>
<span class="ne">ZeroDivisionError</span><span class="p">:</span> <span class="n">integer</span> <span class="n">division</span> <span class="ow">or</span> <span class="n">modulo</span> <span class="n">by</span> <span class="n">zero</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
<p>In the original traceback you can’t even see that code in apsw was
involved. The augmented traceback shows that there were indeed two
function calls within apsw and gives you line numbers should you need
to examine the code. Also note how you are told that the call was in
<cite>user-defined-scalar-foo</cite> (ie you can tell which function was called.)</p>
<p><em>But wait, there is more!!!</em> In order to further aid troubleshooting,
the augmented stack traces make additional information available. Each
frame in the traceback has local variables defined with more
information. You can use <a class="reference internal" href="ext.html#apsw.ext.print_augmented_traceback" title="apsw.ext.print_augmented_traceback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">apsw.ext.print_augmented_traceback()</span></code></a> to
print an exception with the local variables.</p>
<p>Here is a far more complex example from some <a class="reference internal" href="vtable.html#virtualtables"><span class="std std-ref">virtual tables</span></a> code I was writing. The BestIndex method in my code
had returned an incorrect value. The augmented traceback includes
local variables. I can see what was passed in to my method, what I
returned and which item was erroneous. The original traceback is
almost completely useless!</p>
<p>Original traceback:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
  <span class="n">File</span> <span class="s2">&quot;tests.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">1387</span><span class="p">,</span> <span class="ow">in</span> <span class="n">testVtables</span>
    <span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">allconstraints</span><span class="p">)</span>
<span class="ne">TypeError</span><span class="p">:</span> <span class="n">Bad</span> <span class="n">constraint</span> <span class="p">(</span><span class="c1">#2) - it should be one of None, an integer or a tuple of an integer and a boolean</span>
</pre></div>
</div>
<p>Augmented traceback with local variables:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
  <span class="n">File</span> <span class="s2">&quot;tests.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">1387</span><span class="p">,</span> <span class="ow">in</span> <span class="n">testVtables</span>
    <span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">allconstraints</span><span class="p">)</span>
                <span class="n">VTable</span> <span class="o">=</span>  <span class="n">__main__</span><span class="o">.</span><span class="n">VTable</span>
                   <span class="n">cur</span> <span class="o">=</span>  <span class="o">&lt;</span><span class="n">apsw</span><span class="o">.</span><span class="n">Cursor</span> <span class="nb">object</span> <span class="n">at</span> <span class="mh">0x988f30</span><span class="o">&gt;</span>
                     <span class="n">i</span> <span class="o">=</span>  <span class="mi">10</span>
                  <span class="bp">self</span> <span class="o">=</span>  <span class="n">testVtables</span> <span class="p">(</span><span class="n">__main__</span><span class="o">.</span><span class="n">APSW</span><span class="p">)</span>
        <span class="n">allconstraints</span> <span class="o">=</span>  <span class="n">select</span> <span class="n">rowid</span><span class="p">,</span><span class="o">*</span> <span class="kn">from</span> <span class="nn">foo</span> <span class="n">where</span> <span class="n">rowid</span><span class="o">&gt;-</span><span class="mi">1000</span> <span class="o">....</span>

  <span class="n">File</span> <span class="s2">&quot;apsw.c&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">4050</span><span class="p">,</span> <span class="ow">in</span> <span class="n">Cursor_execute</span><span class="o">.</span><span class="n">sqlite3_prepare</span>
            <span class="n">Connection</span> <span class="o">=</span>  <span class="o">&lt;</span><span class="n">apsw</span><span class="o">.</span><span class="n">Connection</span> <span class="nb">object</span> <span class="n">at</span> <span class="mh">0x978800</span><span class="o">&gt;</span>
             <span class="n">statement</span> <span class="o">=</span>  <span class="n">select</span> <span class="n">rowid</span><span class="p">,</span><span class="o">*</span> <span class="kn">from</span> <span class="nn">foo</span> <span class="n">where</span> <span class="n">rowid</span><span class="o">&gt;-</span><span class="mi">1000</span> <span class="o">....</span>

  <span class="n">File</span> <span class="s2">&quot;apsw.c&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">2681</span><span class="p">,</span> <span class="ow">in</span> <span class="n">VirtualTable</span><span class="o">.</span><span class="n">xBestIndex</span>
                  <span class="bp">self</span> <span class="o">=</span>  <span class="o">&lt;</span><span class="n">__main__</span><span class="o">.</span><span class="n">VTable</span> <span class="n">instance</span> <span class="n">at</span> <span class="mh">0x98d8c0</span><span class="o">&gt;</span>
                  <span class="n">args</span> <span class="o">=</span>  <span class="p">(((</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">32</span><span class="p">),</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">8</span><span class="p">),</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">64</span><span class="p">)),</span> <span class="p">((</span><span class="mi">2</span><span class="p">,</span> <span class="kc">False</span><span class="p">),))</span>
                <span class="n">result</span> <span class="o">=</span>  <span class="p">([</span><span class="mi">4</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,),</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="kc">False</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">]],</span> <span class="mi">997</span><span class="p">,</span> <span class="sa">u</span><span class="s1">&#39;</span><span class="se">\xea</span><span class="s1">&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>

  <span class="n">File</span> <span class="s2">&quot;apsw.c&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">2559</span><span class="p">,</span> <span class="ow">in</span> <span class="n">VirtualTable</span><span class="o">.</span><span class="n">xBestIndex</span><span class="o">.</span><span class="n">result_constraint</span>
               <span class="n">indices</span> <span class="o">=</span>  <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,),</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="kc">False</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
                  <span class="bp">self</span> <span class="o">=</span>  <span class="o">&lt;</span><span class="n">__main__</span><span class="o">.</span><span class="n">VTable</span> <span class="n">instance</span> <span class="n">at</span> <span class="mh">0x98d8c0</span><span class="o">&gt;</span>
                <span class="n">result</span> <span class="o">=</span>  <span class="p">([</span><span class="mi">4</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,),</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="kc">False</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">]],</span> <span class="mi">997</span><span class="p">,</span> <span class="sa">u</span><span class="s1">&#39;</span><span class="se">\xea</span><span class="s1">&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
            <span class="n">constraint</span> <span class="o">=</span>  <span class="p">(</span><span class="mi">3</span><span class="p">,)</span>

<span class="ne">TypeError</span><span class="p">:</span> <span class="n">Bad</span> <span class="n">constraint</span> <span class="p">(</span><span class="c1">#2) - it should be one of None, an integer or a tuple of an integer and a boolean</span>
</pre></div>
</div>
</section>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="ext.html" class="btn btn-neutral float-left" title="Various interesting and useful bits of functionality" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="execution.html" class="btn btn-neutral float-right" title="Execution and tracing" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; <a href="copyright.html">Copyright</a> 2004-2024, Roger Binns &lt;rogerb@rogerbinns.com&gt;.
      <span class="lastupdated">Last updated on Jun 16, 2024.
      </span></p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>