GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — python-doc-tw.github.io/library/exceptions.html at master · python-doc-tw/python-doc-tw.github.io Expand file tree/ Copy pathexceptions.htmlMore file actions 1061 lines (960 loc) · 83.6 KB / Copy pathexceptions.htmlFile metadata and controls1061 lines (960 loc) · 83.6 KB 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 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="zh_TW"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>5. 內建的例外 — Python 3.7.0 說明文件</title> <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/translations.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="在 Python 3.7.0 說明文件 中搜尋" href="../_static/opensearch.xml"/> <link rel="author" title="關於這些文件" href="../about.html" /> <link rel="index" title="索引" href="../genindex.html" /> <link rel="search" title="搜尋" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="6. Text Processing Services" href="text.html" /> <link rel="prev" title="4. 內建型態" href="stdtypes.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/3/library/exceptions.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> <script type="text/javascript" src="../_static/switchers.js"></script> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>瀏覽</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">索引</a></li> <li class="right" > <a href="../py-modindex.html" title="Python 模組索引" >模組</a> |</li> <li class="right" > <a href="text.html" title="6. Text Processing Services" accesskey="N">下一頁</a> |</li> <li class="right" > <a href="stdtypes.html" title="4. 內建型態" accesskey="P">上一頁</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <span class="language_switcher_placeholder">zh_TW</span> <span class="version_switcher_placeholder">3.7.0</span> <a href="../index.html">Documentation </a> » </li> <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python 標準函式庫 (Standard Library)</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="built-in-exceptions"> <span id="bltin-exceptions"></span><h1>5. 內建的例外<a class="headerlink" href="#built-in-exceptions" title="本標題的永久連結">¶</a></h1> <p id="index-0">In Python, all exceptions must be instances of a class that derives from <a class="reference internal" href="#BaseException" title="BaseException"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseException</span></code></a>. In a <a class="reference internal" href="../reference/compound_stmts.html#try"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">try</span></code></a> statement with an <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> clause that mentions a particular class, that clause also handles any exception classes derived from that class (but not exception classes from which <em>it</em> is derived). Two exception classes that are not related via subclassing are never equivalent, even if they have the same name.</p> <p id="index-1">The built-in exceptions listed below can be generated by the interpreter or built-in functions. Except where mentioned, they have an 「associated value」 indicating the detailed cause of the error. This may be a string or a tuple of several items of information (e.g., an error code and a string explaining the code). The associated value is usually passed as arguments to the exception class’s constructor.</p> <p>User code can raise built-in exceptions. This can be used to test an exception handler or to report an error condition 「just like」 the situation in which the interpreter raises the same exception; but beware that there is nothing to prevent user code from raising an inappropriate error.</p> <p>The built-in exception classes can be subclassed to define new exceptions; programmers are encouraged to derive new exceptions from the <a class="reference internal" href="#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a> class or one of its subclasses, and not from <a class="reference internal" href="#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a>. More information on defining exceptions is available in the Python Tutorial under <a class="reference internal" href="../tutorial/errors.html#tut-userexceptions"><span class="std std-ref">User-defined Exceptions</span></a>.</p> <p>When raising (or re-raising) an exception in an <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> or <a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a> clause <code class="xref py py-attr docutils literal notranslate"><span class="pre">__context__</span></code> is automatically set to the last exception caught; if the new exception is not handled the traceback that is eventually displayed will include the originating exception(s) and the final exception.</p> <p>When raising a new exception (rather than using a bare <code class="docutils literal notranslate"><span class="pre">raise</span></code> to re-raise the exception currently being handled), the implicit exception context can be supplemented with an explicit cause by using <a class="reference internal" href="../reference/simple_stmts.html#from"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">from</span></code></a> with <a class="reference internal" href="../reference/simple_stmts.html#raise"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">raise</span></code></a>:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">raise</span> <span class="n">new_exc</span> <span class="kn">from</span> <span class="nn">original_exc</span> </pre></div> </div> <p>The expression following <a class="reference internal" href="../reference/simple_stmts.html#from"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">from</span></code></a> must be an exception or <code class="docutils literal notranslate"><span class="pre">None</span></code>. It will be set as <code class="xref py py-attr docutils literal notranslate"><span class="pre">__cause__</span></code> on the raised exception. Setting <code class="xref py py-attr docutils literal notranslate"><span class="pre">__cause__</span></code> also implicitly sets the <code class="xref py py-attr docutils literal notranslate"><span class="pre">__suppress_context__</span></code> attribute to <code class="docutils literal notranslate"><span class="pre">True</span></code>, so that using <code class="docutils literal notranslate"><span class="pre">raise</span> <span class="pre">new_exc</span> <span class="pre">from</span> <span class="pre">None</span></code> effectively replaces the old exception with the new one for display purposes (e.g. converting <a class="reference internal" href="#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> to <a class="reference internal" href="#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a>, while leaving the old exception available in <code class="xref py py-attr docutils literal notranslate"><span class="pre">__context__</span></code> for introspection when debugging.</p> <p>The default traceback display code shows these chained exceptions in addition to the traceback for the exception itself. An explicitly chained exception in <code class="xref py py-attr docutils literal notranslate"><span class="pre">__cause__</span></code> is always shown when present. An implicitly chained exception in <code class="xref py py-attr docutils literal notranslate"><span class="pre">__context__</span></code> is shown only if <code class="xref py py-attr docutils literal notranslate"><span class="pre">__cause__</span></code> is <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">__suppress_context__</span></code> is false.</p> <p>In either case, the exception itself is always shown after any chained exceptions so that the final line of the traceback always shows the last exception that was raised.</p> <div class="section" id="base-classes"> <h2>5.1. Base classes<a class="headerlink" href="#base-classes" title="本標題的永久連結">¶</a></h2> <p>The following exceptions are used mostly as base classes for other exceptions.</p> <dl class="exception"> <dt id="BaseException"> <em class="property">exception </em><code class="descname">BaseException</code><a class="headerlink" href="#BaseException" title="本定義的永久連結">¶</a></dt> <dd><p>The base class for all built-in exceptions. It is not meant to be directly inherited by user-defined classes (for that, use <a class="reference internal" href="#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a>). If <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a> is called on an instance of this class, the representation of the argument(s) to the instance are returned, or the empty string when there were no arguments.</p> <dl class="attribute"> <dt id="BaseException.args"> <code class="descname">args</code><a class="headerlink" href="#BaseException.args" title="本定義的永久連結">¶</a></dt> <dd><p>The tuple of arguments given to the exception constructor. Some built-in exceptions (like <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>) expect a certain number of arguments and assign a special meaning to the elements of this tuple, while others are usually called only with a single string giving an error message.</p> </dd></dl> <dl class="method"> <dt id="BaseException.with_traceback"> <code class="descname">with_traceback</code><span class="sig-paren">(</span><em>tb</em><span class="sig-paren">)</span><a class="headerlink" href="#BaseException.with_traceback" title="本定義的永久連結">¶</a></dt> <dd><p>This method sets <em>tb</em> as the new traceback for the exception and returns the exception object. It is usually used in exception handling code like this:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span> <span class="o">...</span> <span class="k">except</span> <span class="n">SomeException</span><span class="p">:</span> <span class="n">tb</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">exc_info</span><span class="p">()[</span><span class="mi">2</span><span class="p">]</span> <span class="k">raise</span> <span class="n">OtherException</span><span class="p">(</span><span class="o">...</span><span class="p">)</span><span class="o">.</span><span class="n">with_traceback</span><span class="p">(</span><span class="n">tb</span><span class="p">)</span> </pre></div> </div> </dd></dl> </dd></dl> <dl class="exception"> <dt id="Exception"> <em class="property">exception </em><code class="descname">Exception</code><a class="headerlink" href="#Exception" title="本定義的永久連結">¶</a></dt> <dd><p>All built-in, non-system-exiting exceptions are derived from this class. All user-defined exceptions should also be derived from this class.</p> </dd></dl> <dl class="exception"> <dt id="ArithmeticError"> <em class="property">exception </em><code class="descname">ArithmeticError</code><a class="headerlink" href="#ArithmeticError" title="本定義的永久連結">¶</a></dt> <dd><p>The base class for those built-in exceptions that are raised for various arithmetic errors: <a class="reference internal" href="#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a>, <a class="reference internal" href="#ZeroDivisionError" title="ZeroDivisionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZeroDivisionError</span></code></a>, <a class="reference internal" href="#FloatingPointError" title="FloatingPointError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FloatingPointError</span></code></a>.</p> </dd></dl> <dl class="exception"> <dt id="BufferError"> <em class="property">exception </em><code class="descname">BufferError</code><a class="headerlink" href="#BufferError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a <a class="reference internal" href="../c-api/buffer.html#bufferobjects"><span class="std std-ref">buffer</span></a> related operation cannot be performed.</p> </dd></dl> <dl class="exception"> <dt id="LookupError"> <em class="property">exception </em><code class="descname">LookupError</code><a class="headerlink" href="#LookupError" title="本定義的永久連結">¶</a></dt> <dd><p>The base class for the exceptions that are raised when a key or index used on a mapping or sequence is invalid: <a class="reference internal" href="#IndexError" title="IndexError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndexError</span></code></a>, <a class="reference internal" href="#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a>. This can be raised directly by <a class="reference internal" href="codecs.html#codecs.lookup" title="codecs.lookup"><code class="xref py py-func docutils literal notranslate"><span class="pre">codecs.lookup()</span></code></a>.</p> </dd></dl> </div> <div class="section" id="concrete-exceptions"> <h2>5.2. Concrete exceptions<a class="headerlink" href="#concrete-exceptions" title="本標題的永久連結">¶</a></h2> <p>The following exceptions are the exceptions that are usually raised.</p> <dl class="exception"> <dt id="AssertionError"> <em class="property">exception </em><code class="descname">AssertionError</code><a class="headerlink" href="#AssertionError" title="本定義的永久連結">¶</a></dt> <dd><p id="index-2">Raised when an <a class="reference internal" href="../reference/simple_stmts.html#assert"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">assert</span></code></a> statement fails.</p> </dd></dl> <dl class="exception"> <dt id="AttributeError"> <em class="property">exception </em><code class="descname">AttributeError</code><a class="headerlink" href="#AttributeError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when an attribute reference (see <a class="reference internal" href="../reference/expressions.html#attribute-references"><span class="std std-ref">Attribute references</span></a>) or assignment fails. (When an object does not support attribute references or attribute assignments at all, <a class="reference internal" href="#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> is raised.)</p> </dd></dl> <dl class="exception"> <dt id="EOFError"> <em class="property">exception </em><code class="descname">EOFError</code><a class="headerlink" href="#EOFError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when the <a class="reference internal" href="functions.html#input" title="input"><code class="xref py py-func docutils literal notranslate"><span class="pre">input()</span></code></a> function hits an end-of-file condition (EOF) without reading any data. (N.B.: the <code class="xref py py-meth docutils literal notranslate"><span class="pre">io.IOBase.read()</span></code> and <a class="reference internal" href="io.html#io.IOBase.readline" title="io.IOBase.readline"><code class="xref py py-meth docutils literal notranslate"><span class="pre">io.IOBase.readline()</span></code></a> methods return an empty string when they hit EOF.)</p> </dd></dl> <dl class="exception"> <dt id="FloatingPointError"> <em class="property">exception </em><code class="descname">FloatingPointError</code><a class="headerlink" href="#FloatingPointError" title="本定義的永久連結">¶</a></dt> <dd><p>Not currently used.</p> </dd></dl> <dl class="exception"> <dt id="GeneratorExit"> <em class="property">exception </em><code class="descname">GeneratorExit</code><a class="headerlink" href="#GeneratorExit" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a <a class="reference internal" href="../glossary.html#term-generator"><span class="xref std std-term">generator</span></a> or <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> is closed; see <a class="reference internal" href="../reference/expressions.html#generator.close" title="generator.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">generator.close()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#coroutine.close" title="coroutine.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">coroutine.close()</span></code></a>. It directly inherits from <a class="reference internal" href="#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a> instead of <a class="reference internal" href="#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a> since it is technically not an error.</p> </dd></dl> <dl class="exception"> <dt id="ImportError"> <em class="property">exception </em><code class="descname">ImportError</code><a class="headerlink" href="#ImportError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when the <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> statement has troubles trying to load a module. Also raised when the 「from list」 in <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">...</span> <span class="pre">import</span></code> has a name that cannot be found.</p> <p>The <code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">path</span></code> attributes can be set using keyword-only arguments to the constructor. When set they represent the name of the module that was attempted to be imported and the path to any file which triggered the exception, respectively.</p> <div class="versionchanged"> <p><span class="versionmodified">3.3 版更變: </span>Added the <code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">path</span></code> attributes.</p> </div> </dd></dl> <dl class="exception"> <dt id="ModuleNotFoundError"> <em class="property">exception </em><code class="descname">ModuleNotFoundError</code><a class="headerlink" href="#ModuleNotFoundError" title="本定義的永久連結">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> which is raised by <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> when a module could not be located. It is also raised when <code class="docutils literal notranslate"><span class="pre">None</span></code> is found in <a class="reference internal" href="sys.html#sys.modules" title="sys.modules"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.modules</span></code></a>.</p> <div class="versionadded"> <p><span class="versionmodified">3.6 版新加入.</span></p> </div> </dd></dl> <dl class="exception"> <dt id="IndexError"> <em class="property">exception </em><code class="descname">IndexError</code><a class="headerlink" href="#IndexError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a sequence subscript is out of range. (Slice indices are silently truncated to fall in the allowed range; if an index is not an integer, <a class="reference internal" href="#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> is raised.)</p> </dd></dl> <dl class="exception"> <dt id="KeyError"> <em class="property">exception </em><code class="descname">KeyError</code><a class="headerlink" href="#KeyError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a mapping (dictionary) key is not found in the set of existing keys.</p> </dd></dl> <dl class="exception"> <dt id="KeyboardInterrupt"> <em class="property">exception </em><code class="descname">KeyboardInterrupt</code><a class="headerlink" href="#KeyboardInterrupt" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when the user hits the interrupt key (normally <kbd class="kbd docutils literal notranslate">Control-C</kbd> or <kbd class="kbd docutils literal notranslate">Delete</kbd>). During execution, a check for interrupts is made regularly. The exception inherits from <a class="reference internal" href="#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a> so as to not be accidentally caught by code that catches <a class="reference internal" href="#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a> and thus prevent the interpreter from exiting.</p> </dd></dl> <dl class="exception"> <dt id="MemoryError"> <em class="property">exception </em><code class="descname">MemoryError</code><a class="headerlink" href="#MemoryError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when an operation runs out of memory but the situation may still be rescued (by deleting some objects). The associated value is a string indicating what kind of (internal) operation ran out of memory. Note that because of the underlying memory management architecture (C’s <code class="xref c c-func docutils literal notranslate"><span class="pre">malloc()</span></code> function), the interpreter may not always be able to completely recover from this situation; it nevertheless raises an exception so that a stack traceback can be printed, in case a run-away program was the cause.</p> </dd></dl> <dl class="exception"> <dt id="NameError"> <em class="property">exception </em><code class="descname">NameError</code><a class="headerlink" href="#NameError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a local or global name is not found. This applies only to unqualified names. The associated value is an error message that includes the name that could not be found.</p> </dd></dl> <dl class="exception"> <dt id="NotImplementedError"> <em class="property">exception </em><code class="descname">NotImplementedError</code><a class="headerlink" href="#NotImplementedError" title="本定義的永久連結">¶</a></dt> <dd><p>This exception is derived from <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>. In user defined base classes, abstract methods should raise this exception when they require derived classes to override the method, or while the class is being developed to indicate that the real implementation still needs to be added.</p> <div class="admonition note"> <p class="first admonition-title">備註</p> <p class="last">It should not be used to indicate that an operator or method is not meant to be supported at all – in that case either leave the operator / method undefined or, if a subclass, set it to <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-data docutils literal notranslate"><span class="pre">None</span></code></a>.</p> </div> <div class="admonition note"> <p class="first admonition-title">備註</p> <p class="last"><code class="docutils literal notranslate"><span class="pre">NotImplementedError</span></code> and <code class="docutils literal notranslate"><span class="pre">NotImplemented</span></code> are not interchangeable, even though they have similar names and purposes. See <a class="reference internal" href="constants.html#NotImplemented" title="NotImplemented"><code class="xref py py-data docutils literal notranslate"><span class="pre">NotImplemented</span></code></a> for details on when to use it.</p> </div> </dd></dl> <dl class="exception"> <dt id="OSError"> <em class="property">exception </em><code class="descname">OSError</code><span class="sig-paren">(</span><span class="optional">[</span><em>arg</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#OSError" title="本定義的永久連結">¶</a></dt> <dt> <em class="property">exception </em><code class="descname">OSError</code><span class="sig-paren">(</span><em>errno</em>, <em>strerror</em><span class="optional">[</span>, <em>filename</em><span class="optional">[</span>, <em>winerror</em><span class="optional">[</span>, <em>filename2</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span></dt> <dd><p id="index-3">This exception is raised when a system function returns a system-related error, including I/O failures such as 「file not found」 or 「disk full」 (not for illegal argument types or other incidental errors).</p> <p>The second form of the constructor sets the corresponding attributes, described below. The attributes default to <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> if not specified. For backwards compatibility, if three arguments are passed, the <a class="reference internal" href="#BaseException.args" title="BaseException.args"><code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code></a> attribute contains only a 2-tuple of the first two constructor arguments.</p> <p>The constructor often actually returns a subclass of <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>, as described in <a class="reference internal" href="#os-exceptions">OS exceptions</a> below. The particular subclass depends on the final <a class="reference internal" href="#OSError.errno" title="OSError.errno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">errno</span></code></a> value. This behaviour only occurs when constructing <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> directly or via an alias, and is not inherited when subclassing.</p> <dl class="attribute"> <dt id="OSError.errno"> <code class="descname">errno</code><a class="headerlink" href="#OSError.errno" title="本定義的永久連結">¶</a></dt> <dd><p>A numeric error code from the C variable <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code>.</p> </dd></dl> <dl class="attribute"> <dt id="OSError.winerror"> <code class="descname">winerror</code><a class="headerlink" href="#OSError.winerror" title="本定義的永久連結">¶</a></dt> <dd><p>Under Windows, this gives you the native Windows error code. The <a class="reference internal" href="#OSError.errno" title="OSError.errno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">errno</span></code></a> attribute is then an approximate translation, in POSIX terms, of that native error code.</p> <p>Under Windows, if the <em>winerror</em> constructor argument is an integer, the <a class="reference internal" href="#OSError.errno" title="OSError.errno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">errno</span></code></a> attribute is determined from the Windows error code, and the <em>errno</em> argument is ignored. On other platforms, the <em>winerror</em> argument is ignored, and the <a class="reference internal" href="#OSError.winerror" title="OSError.winerror"><code class="xref py py-attr docutils literal notranslate"><span class="pre">winerror</span></code></a> attribute does not exist.</p> </dd></dl> <dl class="attribute"> <dt id="OSError.strerror"> <code class="descname">strerror</code><a class="headerlink" href="#OSError.strerror" title="本定義的永久連結">¶</a></dt> <dd><p>The corresponding error message, as provided by the operating system. It is formatted by the C functions <code class="xref c c-func docutils literal notranslate"><span class="pre">perror()</span></code> under POSIX, and <code class="xref c c-func docutils literal notranslate"><span class="pre">FormatMessage()</span></code> under Windows.</p> </dd></dl> <dl class="attribute"> <dt id="OSError.filename"> <code class="descname">filename</code><a class="headerlink" href="#OSError.filename" title="本定義的永久連結">¶</a></dt> <dt id="OSError.filename2"> <code class="descname">filename2</code><a class="headerlink" href="#OSError.filename2" title="本定義的永久連結">¶</a></dt> <dd><p>For exceptions that involve a file system path (such as <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> or <a class="reference internal" href="os.html#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.unlink()</span></code></a>), <a class="reference internal" href="#OSError.filename" title="OSError.filename"><code class="xref py py-attr docutils literal notranslate"><span class="pre">filename</span></code></a> is the file name passed to the function. For functions that involve two file system paths (such as <a class="reference internal" href="os.html#os.rename" title="os.rename"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.rename()</span></code></a>), <a class="reference internal" href="#OSError.filename2" title="OSError.filename2"><code class="xref py py-attr docutils literal notranslate"><span class="pre">filename2</span></code></a> corresponds to the second file name passed to the function.</p> </dd></dl> <div class="versionchanged"> <p><span class="versionmodified">3.3 版更變: </span><a class="reference internal" href="#EnvironmentError" title="EnvironmentError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">EnvironmentError</span></code></a>, <a class="reference internal" href="#IOError" title="IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a>, <a class="reference internal" href="#WindowsError" title="WindowsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">WindowsError</span></code></a>, <a class="reference internal" href="socket.html#socket.error" title="socket.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">socket.error</span></code></a>, <a class="reference internal" href="select.html#select.error" title="select.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">select.error</span></code></a> and <code class="xref py py-exc docutils literal notranslate"><span class="pre">mmap.error</span></code> have been merged into <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>, and the constructor may return a subclass.</p> </div> <div class="versionchanged"> <p><span class="versionmodified">3.4 版更變: </span>The <a class="reference internal" href="#OSError.filename" title="OSError.filename"><code class="xref py py-attr docutils literal notranslate"><span class="pre">filename</span></code></a> attribute is now the original file name passed to the function, instead of the name encoded to or decoded from the filesystem encoding. Also, the <em>filename2</em> constructor argument and attribute was added.</p> </div> </dd></dl> <dl class="exception"> <dt id="OverflowError"> <em class="property">exception </em><code class="descname">OverflowError</code><a class="headerlink" href="#OverflowError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when the result of an arithmetic operation is too large to be represented. This cannot occur for integers (which would rather raise <a class="reference internal" href="#MemoryError" title="MemoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">MemoryError</span></code></a> than give up). However, for historical reasons, OverflowError is sometimes raised for integers that are outside a required range. Because of the lack of standardization of floating point exception handling in C, most floating point operations are not checked.</p> </dd></dl> <dl class="exception"> <dt id="RecursionError"> <em class="property">exception </em><code class="descname">RecursionError</code><a class="headerlink" href="#RecursionError" title="本定義的永久連結">¶</a></dt> <dd><p>This exception is derived from <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>. It is raised when the interpreter detects that the maximum recursion depth (see <a class="reference internal" href="sys.html#sys.getrecursionlimit" title="sys.getrecursionlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getrecursionlimit()</span></code></a>) is exceeded.</p> <div class="versionadded"> <p><span class="versionmodified">3.5 版新加入: </span>Previously, a plain <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> was raised.</p> </div> </dd></dl> <dl class="exception"> <dt id="ReferenceError"> <em class="property">exception </em><code class="descname">ReferenceError</code><a class="headerlink" href="#ReferenceError" title="本定義的永久連結">¶</a></dt> <dd><p>This exception is raised when a weak reference proxy, created by the <a class="reference internal" href="weakref.html#weakref.proxy" title="weakref.proxy"><code class="xref py py-func docutils literal notranslate"><span class="pre">weakref.proxy()</span></code></a> function, is used to access an attribute of the referent after it has been garbage collected. For more information on weak references, see the <a class="reference internal" href="weakref.html#module-weakref" title="weakref: Support for weak references and weak dictionaries."><code class="xref py py-mod docutils literal notranslate"><span class="pre">weakref</span></code></a> module.</p> </dd></dl> <dl class="exception"> <dt id="RuntimeError"> <em class="property">exception </em><code class="descname">RuntimeError</code><a class="headerlink" href="#RuntimeError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when an error is detected that doesn’t fall in any of the other categories. The associated value is a string indicating what precisely went wrong.</p> </dd></dl> <dl class="exception"> <dt id="StopIteration"> <em class="property">exception </em><code class="descname">StopIteration</code><a class="headerlink" href="#StopIteration" title="本定義的永久連結">¶</a></dt> <dd><p>Raised by built-in function <a class="reference internal" href="functions.html#next" title="next"><code class="xref py py-func docutils literal notranslate"><span class="pre">next()</span></code></a> and an <a class="reference internal" href="../glossary.html#term-iterator"><span class="xref std std-term">iterator</span></a>’s <a class="reference internal" href="stdtypes.html#iterator.__next__" title="iterator.__next__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__next__()</span></code></a> method to signal that there are no further items produced by the iterator.</p> <p>The exception object has a single attribute <code class="xref py py-attr docutils literal notranslate"><span class="pre">value</span></code>, which is given as an argument when constructing the exception, and defaults to <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>.</p> <p>When a <a class="reference internal" href="../glossary.html#term-generator"><span class="xref std std-term">generator</span></a> or <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> function returns, a new <a class="reference internal" href="#StopIteration" title="StopIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code></a> instance is raised, and the value returned by the function is used as the <code class="xref py py-attr docutils literal notranslate"><span class="pre">value</span></code> parameter to the constructor of the exception.</p> <p>If a generator code directly or indirectly raises <a class="reference internal" href="#StopIteration" title="StopIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code></a>, it is converted into a <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> (retaining the <a class="reference internal" href="#StopIteration" title="StopIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code></a> as the new exception’s cause).</p> <div class="versionchanged"> <p><span class="versionmodified">3.3 版更變: </span>Added <code class="docutils literal notranslate"><span class="pre">value</span></code> attribute and the ability for generator functions to use it to return a value.</p> </div> <div class="versionchanged"> <p><span class="versionmodified">3.5 版更變: </span>Introduced the RuntimeError transformation via <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">generator_stop</span></code>, see <span class="target" id="index-4"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0479"><strong>PEP 479</strong></a>.</p> </div> <div class="versionchanged"> <p><span class="versionmodified">3.7 版更變: </span>Enable <span class="target" id="index-5"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0479"><strong>PEP 479</strong></a> for all code by default: a <a class="reference internal" href="#StopIteration" title="StopIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code></a> error raised in a generator is transformed into a <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>.</p> </div> </dd></dl> <dl class="exception"> <dt id="StopAsyncIteration"> <em class="property">exception </em><code class="descname">StopAsyncIteration</code><a class="headerlink" href="#StopAsyncIteration" title="本定義的永久連結">¶</a></dt> <dd><p>Must be raised by <a class="reference internal" href="../reference/datamodel.html#object.__anext__" title="object.__anext__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__anext__()</span></code></a> method of an <a class="reference internal" href="../glossary.html#term-asynchronous-iterator"><span class="xref std std-term">asynchronous iterator</span></a> object to stop the iteration.</p> <div class="versionadded"> <p><span class="versionmodified">3.5 版新加入.</span></p> </div> </dd></dl> <dl class="exception"> <dt id="SyntaxError"> <em class="property">exception </em><code class="descname">SyntaxError</code><a class="headerlink" href="#SyntaxError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when the parser encounters a syntax error. This may occur in an <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> statement, in a call to the built-in functions <a class="reference internal" href="functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a> or <a class="reference internal" href="functions.html#eval" title="eval"><code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code></a>, or when reading the initial script or standard input (also interactively).</p> <p>Instances of this class have attributes <code class="xref py py-attr docutils literal notranslate"><span class="pre">filename</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">lineno</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">offset</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">text</span></code> for easier access to the details. <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a> of the exception instance returns only the message.</p> </dd></dl> <dl class="exception"> <dt id="IndentationError"> <em class="property">exception </em><code class="descname">IndentationError</code><a class="headerlink" href="#IndentationError" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for syntax errors related to incorrect indentation. This is a subclass of <a class="reference internal" href="#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>.</p> </dd></dl> <dl class="exception"> <dt id="TabError"> <em class="property">exception </em><code class="descname">TabError</code><a class="headerlink" href="#TabError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when indentation contains an inconsistent use of tabs and spaces. This is a subclass of <a class="reference internal" href="#IndentationError" title="IndentationError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndentationError</span></code></a>.</p> </dd></dl> <dl class="exception"> <dt id="SystemError"> <em class="property">exception </em><code class="descname">SystemError</code><a class="headerlink" href="#SystemError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when the interpreter finds an internal error, but the situation does not look so serious to cause it to abandon all hope. The associated value is a string indicating what went wrong (in low-level terms).</p> <p>You should report this to the author or maintainer of your Python interpreter. Be sure to report the version of the Python interpreter (<code class="docutils literal notranslate"><span class="pre">sys.version</span></code>; it is also printed at the start of an interactive Python session), the exact error message (the exception’s associated value) and if possible the source of the program that triggered the error.</p> </dd></dl> <dl class="exception"> <dt id="SystemExit"> <em class="property">exception </em><code class="descname">SystemExit</code><a class="headerlink" href="#SystemExit" title="本定義的永久連結">¶</a></dt> <dd><p>This exception is raised by the <a class="reference internal" href="sys.html#sys.exit" title="sys.exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exit()</span></code></a> function. It inherits from <a class="reference internal" href="#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a> instead of <a class="reference internal" href="#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a> so that it is not accidentally caught by code that catches <a class="reference internal" href="#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a>. This allows the exception to properly propagate up and cause the interpreter to exit. When it is not handled, the Python interpreter exits; no stack traceback is printed. The constructor accepts the same optional argument passed to <a class="reference internal" href="sys.html#sys.exit" title="sys.exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exit()</span></code></a>. If the value is an integer, it specifies the system exit status (passed to C’s <code class="xref c c-func docutils literal notranslate"><span class="pre">exit()</span></code> function); if it is <code class="docutils literal notranslate"><span class="pre">None</span></code>, the exit status is zero; if it has another type (such as a string), the object’s value is printed and the exit status is one.</p> <p>A call to <a class="reference internal" href="sys.html#sys.exit" title="sys.exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exit()</span></code></a> is translated into an exception so that clean-up handlers (<a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a> clauses of <a class="reference internal" href="../reference/compound_stmts.html#try"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">try</span></code></a> statements) can be executed, and so that a debugger can execute a script without running the risk of losing control. The <a class="reference internal" href="os.html#os._exit" title="os._exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">os._exit()</span></code></a> function can be used if it is absolutely positively necessary to exit immediately (for example, in the child process after a call to <a class="reference internal" href="os.html#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fork()</span></code></a>).</p> <dl class="attribute"> <dt id="SystemExit.code"> <code class="descname">code</code><a class="headerlink" href="#SystemExit.code" title="本定義的永久連結">¶</a></dt> <dd><p>The exit status or error message that is passed to the constructor. (Defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code>.)</p> </dd></dl> </dd></dl> <dl class="exception"> <dt id="TypeError"> <em class="property">exception </em><code class="descname">TypeError</code><a class="headerlink" href="#TypeError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about the type mismatch.</p> <p>This exception may be raised by user code to indicate that an attempted operation on an object is not supported, and is not meant to be. If an object is meant to support a given operation but has not yet provided an implementation, <a class="reference internal" href="#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> is the proper exception to raise.</p> <p>Passing arguments of the wrong type (e.g. passing a <a class="reference internal" href="stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> when an <a class="reference internal" href="functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> is expected) should result in a <a class="reference internal" href="#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a <a class="reference internal" href="#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>.</p> </dd></dl> <dl class="exception"> <dt id="UnboundLocalError"> <em class="property">exception </em><code class="descname">UnboundLocalError</code><a class="headerlink" href="#UnboundLocalError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable. This is a subclass of <a class="reference internal" href="#NameError" title="NameError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NameError</span></code></a>.</p> </dd></dl> <dl class="exception"> <dt id="UnicodeError"> <em class="property">exception </em><code class="descname">UnicodeError</code><a class="headerlink" href="#UnicodeError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a Unicode-related encoding or decoding error occurs. It is a subclass of <a class="reference internal" href="#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>.</p> <p><a class="reference internal" href="#UnicodeError" title="UnicodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeError</span></code></a> has attributes that describe the encoding or decoding error. For example, <code class="docutils literal notranslate"><span class="pre">err.object[err.start:err.end]</span></code> gives the particular invalid input that the codec failed on.</p> <dl class="attribute"> <dt id="UnicodeError.encoding"> <code class="descname">encoding</code><a class="headerlink" href="#UnicodeError.encoding" title="本定義的永久連結">¶</a></dt> <dd><p>The name of the encoding that raised the error.</p> </dd></dl> <dl class="attribute"> <dt id="UnicodeError.reason"> <code class="descname">reason</code><a class="headerlink" href="#UnicodeError.reason" title="本定義的永久連結">¶</a></dt> <dd><p>A string describing the specific codec error.</p> </dd></dl> <dl class="attribute"> <dt id="UnicodeError.object"> <code class="descname">object</code><a class="headerlink" href="#UnicodeError.object" title="本定義的永久連結">¶</a></dt> <dd><p>The object the codec was attempting to encode or decode.</p> </dd></dl> <dl class="attribute"> <dt id="UnicodeError.start"> <code class="descname">start</code><a class="headerlink" href="#UnicodeError.start" title="本定義的永久連結">¶</a></dt> <dd><p>The first index of invalid data in <a class="reference internal" href="functions.html#object" title="object"><code class="xref py py-attr docutils literal notranslate"><span class="pre">object</span></code></a>.</p> </dd></dl> <dl class="attribute"> <dt id="UnicodeError.end"> <code class="descname">end</code><a class="headerlink" href="#UnicodeError.end" title="本定義的永久連結">¶</a></dt> <dd><p>The index after the last invalid data in <a class="reference internal" href="functions.html#object" title="object"><code class="xref py py-attr docutils literal notranslate"><span class="pre">object</span></code></a>.</p> </dd></dl> </dd></dl> <dl class="exception"> <dt id="UnicodeEncodeError"> <em class="property">exception </em><code class="descname">UnicodeEncodeError</code><a class="headerlink" href="#UnicodeEncodeError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a Unicode-related error occurs during encoding. It is a subclass of <a class="reference internal" href="#UnicodeError" title="UnicodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeError</span></code></a>.</p> </dd></dl> <dl class="exception"> <dt id="UnicodeDecodeError"> <em class="property">exception </em><code class="descname">UnicodeDecodeError</code><a class="headerlink" href="#UnicodeDecodeError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a Unicode-related error occurs during decoding. It is a subclass of <a class="reference internal" href="#UnicodeError" title="UnicodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeError</span></code></a>.</p> </dd></dl> <dl class="exception"> <dt id="UnicodeTranslateError"> <em class="property">exception </em><code class="descname">UnicodeTranslateError</code><a class="headerlink" href="#UnicodeTranslateError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a Unicode-related error occurs during translating. It is a subclass of <a class="reference internal" href="#UnicodeError" title="UnicodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeError</span></code></a>.</p> </dd></dl> <dl class="exception"> <dt id="ValueError"> <em class="property">exception </em><code class="descname">ValueError</code><a class="headerlink" href="#ValueError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as <a class="reference internal" href="#IndexError" title="IndexError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndexError</span></code></a>.</p> </dd></dl> <dl class="exception"> <dt id="ZeroDivisionError"> <em class="property">exception </em><code class="descname">ZeroDivisionError</code><a class="headerlink" href="#ZeroDivisionError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when the second argument of a division or modulo operation is zero. The associated value is a string indicating the type of the operands and the operation.</p> </dd></dl> <p>The following exceptions are kept for compatibility with previous versions; starting from Python 3.3, they are aliases of <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>.</p> <dl class="exception"> <dt id="EnvironmentError"> <em class="property">exception </em><code class="descname">EnvironmentError</code><a class="headerlink" href="#EnvironmentError" title="本定義的永久連結">¶</a></dt> <dd></dd></dl> <dl class="exception"> <dt id="IOError"> <em class="property">exception </em><code class="descname">IOError</code><a class="headerlink" href="#IOError" title="本定義的永久連結">¶</a></dt> <dd></dd></dl> <dl class="exception"> <dt id="WindowsError"> <em class="property">exception </em><code class="descname">WindowsError</code><a class="headerlink" href="#WindowsError" title="本定義的永久連結">¶</a></dt> <dd><p>Only available on Windows.</p> </dd></dl> <div class="section" id="os-exceptions"> <h3>5.2.1. OS exceptions<a class="headerlink" href="#os-exceptions" title="本標題的永久連結">¶</a></h3> <p>The following exceptions are subclasses of <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>, they get raised depending on the system error code.</p> <dl class="exception"> <dt id="BlockingIOError"> <em class="property">exception </em><code class="descname">BlockingIOError</code><a class="headerlink" href="#BlockingIOError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when an operation would block on an object (e.g. socket) set for non-blocking operation. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">EAGAIN</span></code>, <code class="docutils literal notranslate"><span class="pre">EALREADY</span></code>, <code class="docutils literal notranslate"><span class="pre">EWOULDBLOCK</span></code> and <code class="docutils literal notranslate"><span class="pre">EINPROGRESS</span></code>.</p> <p>In addition to those of <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>, <a class="reference internal" href="#BlockingIOError" title="BlockingIOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BlockingIOError</span></code></a> can have one more attribute:</p> <dl class="attribute"> <dt id="BlockingIOError.characters_written"> <code class="descname">characters_written</code><a class="headerlink" href="#BlockingIOError.characters_written" title="本定義的永久連結">¶</a></dt> <dd><p>An integer containing the number of characters written to the stream before it blocked. This attribute is available when using the buffered I/O classes from the <a class="reference internal" href="io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code></a> module.</p> </dd></dl> </dd></dl> <dl class="exception"> <dt id="ChildProcessError"> <em class="property">exception </em><code class="descname">ChildProcessError</code><a class="headerlink" href="#ChildProcessError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when an operation on a child process failed. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">ECHILD</span></code>.</p> </dd></dl> <dl class="exception"> <dt id="ConnectionError"> <em class="property">exception </em><code class="descname">ConnectionError</code><a class="headerlink" href="#ConnectionError" title="本定義的永久連結">¶</a></dt> <dd><p>A base class for connection-related issues.</p> <p>Subclasses are <a class="reference internal" href="#BrokenPipeError" title="BrokenPipeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BrokenPipeError</span></code></a>, <a class="reference internal" href="#ConnectionAbortedError" title="ConnectionAbortedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionAbortedError</span></code></a>, <a class="reference internal" href="#ConnectionRefusedError" title="ConnectionRefusedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionRefusedError</span></code></a> and <a class="reference internal" href="#ConnectionResetError" title="ConnectionResetError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionResetError</span></code></a>.</p> </dd></dl> <dl class="exception"> <dt id="BrokenPipeError"> <em class="property">exception </em><code class="descname">BrokenPipeError</code><a class="headerlink" href="#BrokenPipeError" title="本定義的永久連結">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a>, raised when trying to write on a pipe while the other end has been closed, or trying to write on a socket which has been shutdown for writing. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">EPIPE</span></code> and <code class="docutils literal notranslate"><span class="pre">ESHUTDOWN</span></code>.</p> </dd></dl> <dl class="exception"> <dt id="ConnectionAbortedError"> <em class="property">exception </em><code class="descname">ConnectionAbortedError</code><a class="headerlink" href="#ConnectionAbortedError" title="本定義的永久連結">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a>, raised when a connection attempt is aborted by the peer. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">ECONNABORTED</span></code>.</p> </dd></dl> <dl class="exception"> <dt id="ConnectionRefusedError"> <em class="property">exception </em><code class="descname">ConnectionRefusedError</code><a class="headerlink" href="#ConnectionRefusedError" title="本定義的永久連結">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a>, raised when a connection attempt is refused by the peer. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">ECONNREFUSED</span></code>.</p> </dd></dl> <dl class="exception"> <dt id="ConnectionResetError"> <em class="property">exception </em><code class="descname">ConnectionResetError</code><a class="headerlink" href="#ConnectionResetError" title="本定義的永久連結">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a>, raised when a connection is reset by the peer. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">ECONNRESET</span></code>.</p> </dd></dl> <dl class="exception"> <dt id="FileExistsError"> <em class="property">exception </em><code class="descname">FileExistsError</code><a class="headerlink" href="#FileExistsError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when trying to create a file or directory which already exists. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">EEXIST</span></code>.</p> </dd></dl> <dl class="exception"> <dt id="FileNotFoundError"> <em class="property">exception </em><code class="descname">FileNotFoundError</code><a class="headerlink" href="#FileNotFoundError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a file or directory is requested but doesn’t exist. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">ENOENT</span></code>.</p> </dd></dl> <dl class="exception"> <dt id="InterruptedError"> <em class="property">exception </em><code class="descname">InterruptedError</code><a class="headerlink" href="#InterruptedError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a system call is interrupted by an incoming signal. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.EINTR" title="errno.EINTR"><code class="xref py py-data docutils literal notranslate"><span class="pre">EINTR</span></code></a>.</p> <div class="versionchanged"> <p><span class="versionmodified">3.5 版更變: </span>Python now retries system calls when a syscall is interrupted by a signal, except if the signal handler raises an exception (see <span class="target" id="index-6"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0475"><strong>PEP 475</strong></a> for the rationale), instead of raising <a class="reference internal" href="#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a>.</p> </div> </dd></dl> <dl class="exception"> <dt id="IsADirectoryError"> <em class="property">exception </em><code class="descname">IsADirectoryError</code><a class="headerlink" href="#IsADirectoryError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a file operation (such as <a class="reference internal" href="os.html#os.remove" title="os.remove"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.remove()</span></code></a>) is requested on a directory. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">EISDIR</span></code>.</p> </dd></dl> <dl class="exception"> <dt id="NotADirectoryError"> <em class="property">exception </em><code class="descname">NotADirectoryError</code><a class="headerlink" href="#NotADirectoryError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a directory operation (such as <a class="reference internal" href="os.html#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listdir()</span></code></a>) is requested on something which is not a directory. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">ENOTDIR</span></code>.</p> </dd></dl> <dl class="exception"> <dt id="PermissionError"> <em class="property">exception </em><code class="descname">PermissionError</code><a class="headerlink" href="#PermissionError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when trying to run an operation without the adequate access rights - for example filesystem permissions. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">EACCES</span></code> and <code class="docutils literal notranslate"><span class="pre">EPERM</span></code>.</p> </dd></dl> <dl class="exception"> <dt id="ProcessLookupError"> <em class="property">exception </em><code class="descname">ProcessLookupError</code><a class="headerlink" href="#ProcessLookupError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a given process doesn’t exist. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">ESRCH</span></code>.</p> </dd></dl> <dl class="exception"> <dt id="TimeoutError"> <em class="property">exception </em><code class="descname">TimeoutError</code><a class="headerlink" href="#TimeoutError" title="本定義的永久連結">¶</a></dt> <dd><p>Raised when a system function timed out at the system level. Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <code class="docutils literal notranslate"><span class="pre">ETIMEDOUT</span></code>.</p> </dd></dl> <div class="versionadded"> <p><span class="versionmodified">3.3 版新加入: </span>All the above <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> subclasses were added.</p> </div> <div class="admonition seealso"> <p class="first admonition-title">也參考</p> <p class="last"><span class="target" id="index-7"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3151"><strong>PEP 3151</strong></a> - Reworking the OS and IO exception hierarchy</p> </div> </div> </div> <div class="section" id="warnings"> <span id="warning-categories-as-exceptions"></span><h2>5.3. Warnings<a class="headerlink" href="#warnings" title="本標題的永久連結">¶</a></h2> <p>The following exceptions are used as warning categories; see the <a class="reference internal" href="warnings.html#warning-categories"><span class="std std-ref">Warning Categories</span></a> documentation for more details.</p> <dl class="exception"> <dt id="Warning"> <em class="property">exception </em><code class="descname">Warning</code><a class="headerlink" href="#Warning" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for warning categories.</p> </dd></dl> <dl class="exception"> <dt id="UserWarning"> <em class="property">exception </em><code class="descname">UserWarning</code><a class="headerlink" href="#UserWarning" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for warnings generated by user code.</p> </dd></dl> <dl class="exception"> <dt id="DeprecationWarning"> <em class="property">exception </em><code class="descname">DeprecationWarning</code><a class="headerlink" href="#DeprecationWarning" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for warnings about deprecated features when those warnings are intended for other Python developers.</p> </dd></dl> <dl class="exception"> <dt id="PendingDeprecationWarning"> <em class="property">exception </em><code class="descname">PendingDeprecationWarning</code><a class="headerlink" href="#PendingDeprecationWarning" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for warnings about features which will be deprecated in the future.</p> </dd></dl> <dl class="exception"> <dt id="SyntaxWarning"> <em class="property">exception </em><code class="descname">SyntaxWarning</code><a class="headerlink" href="#SyntaxWarning" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for warnings about dubious syntax.</p> </dd></dl> <dl class="exception"> <dt id="RuntimeWarning"> <em class="property">exception </em><code class="descname">RuntimeWarning</code><a class="headerlink" href="#RuntimeWarning" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for warnings about dubious runtime behavior.</p> </dd></dl> <dl class="exception"> <dt id="FutureWarning"> <em class="property">exception </em><code class="descname">FutureWarning</code><a class="headerlink" href="#FutureWarning" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for warnings about deprecated features when those warnings are intended for end users of applications that are written in Python.</p> </dd></dl> <dl class="exception"> <dt id="ImportWarning"> <em class="property">exception </em><code class="descname">ImportWarning</code><a class="headerlink" href="#ImportWarning" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for warnings about probable mistakes in module imports.</p> </dd></dl> <dl class="exception"> <dt id="UnicodeWarning"> <em class="property">exception </em><code class="descname">UnicodeWarning</code><a class="headerlink" href="#UnicodeWarning" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for warnings related to Unicode.</p> </dd></dl> <dl class="exception"> <dt id="BytesWarning"> <em class="property">exception </em><code class="descname">BytesWarning</code><a class="headerlink" href="#BytesWarning" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for warnings related to <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> and <a class="reference internal" href="stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a>.</p> </dd></dl> <dl class="exception"> <dt id="ResourceWarning"> <em class="property">exception </em><code class="descname">ResourceWarning</code><a class="headerlink" href="#ResourceWarning" title="本定義的永久連結">¶</a></dt> <dd><p>Base class for warnings related to resource usage. Ignored by the default warning filters.</p> <div class="versionadded"> <p><span class="versionmodified">3.2 版新加入.</span></p> </div> </dd></dl> </div> <div class="section" id="exception-hierarchy"> <h2>5.4. Exception hierarchy<a class="headerlink" href="#exception-hierarchy" title="本標題的永久連結">¶</a></h2> <p>The class hierarchy for built-in exceptions is:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="ne">BaseException</span> <span class="o">+--</span> <span class="ne">SystemExit</span> <span class="o">+--</span> <span class="ne">KeyboardInterrupt</span> <span class="o">+--</span> <span class="ne">GeneratorExit</span> <span class="o">+--</span> <span class="ne">Exception</span> <span class="o">+--</span> <span class="ne">StopIteration</span> <span class="o">+--</span> <span class="n">StopAsyncIteration</span> <span class="o">+--</span> <span class="ne">ArithmeticError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">FloatingPointError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">OverflowError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">ZeroDivisionError</span> <span class="o">+--</span> <span class="ne">AssertionError</span> <span class="o">+--</span> <span class="ne">AttributeError</span> <span class="o">+--</span> <span class="ne">BufferError</span> <span class="o">+--</span> <span class="ne">EOFError</span> <span class="o">+--</span> <span class="ne">ImportError</span> <span class="o">|</span> <span class="o">+--</span> <span class="n">ModuleNotFoundError</span> <span class="o">+--</span> <span class="ne">LookupError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">IndexError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">KeyError</span> <span class="o">+--</span> <span class="ne">MemoryError</span> <span class="o">+--</span> <span class="ne">NameError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">UnboundLocalError</span> <span class="o">+--</span> <span class="ne">OSError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">BlockingIOError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">ChildProcessError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">ConnectionError</span> <span class="o">|</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">BrokenPipeError</span> <span class="o">|</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">ConnectionAbortedError</span> <span class="o">|</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">ConnectionRefusedError</span> <span class="o">|</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">ConnectionResetError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">FileExistsError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">FileNotFoundError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">InterruptedError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">IsADirectoryError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">NotADirectoryError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">PermissionError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">ProcessLookupError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">TimeoutError</span> <span class="o">+--</span> <span class="ne">ReferenceError</span> <span class="o">+--</span> <span class="ne">RuntimeError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">NotImplementedError</span> <span class="o">|</span> <span class="o">+--</span> <span class="n">RecursionError</span> <span class="o">+--</span> <span class="ne">SyntaxError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">IndentationError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">TabError</span> <span class="o">+--</span> <span class="ne">SystemError</span> <span class="o">+--</span> <span class="ne">TypeError</span> <span class="o">+--</span> <span class="ne">ValueError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">UnicodeError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">UnicodeDecodeError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">UnicodeEncodeError</span> <span class="o">|</span> <span class="o">+--</span> <span class="ne">UnicodeTranslateError</span> <span class="o">+--</span> <span class="ne">Warning</span> <span class="o">+--</span> <span class="ne">DeprecationWarning</span> <span class="o">+--</span> <span class="ne">PendingDeprecationWarning</span> <span class="o">+--</span> <span class="ne">RuntimeWarning</span> <span class="o">+--</span> <span class="ne">SyntaxWarning</span> <span class="o">+--</span> <span class="ne">UserWarning</span> <span class="o">+--</span> <span class="ne">FutureWarning</span> <span class="o">+--</span> <span class="ne">ImportWarning</span> <span class="o">+--</span> <span class="ne">UnicodeWarning</span> <span class="o">+--</span> <span class="ne">BytesWarning</span> <span class="o">+--</span> <span class="ne">ResourceWarning</span> </pre></div> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">目錄</a></h3> <ul> <li><a class="reference internal" href="#">5. 內建的例外</a><ul> <li><a class="reference internal" href="#base-classes">5.1. Base classes</a></li> <li><a class="reference internal" href="#concrete-exceptions">5.2. Concrete exceptions</a><ul> <li><a class="reference internal" href="#os-exceptions">5.2.1. OS exceptions</a></li> </ul> </li> <li><a class="reference internal" href="#warnings">5.3. Warnings</a></li> <li><a class="reference internal" href="#exception-hierarchy">5.4. Exception hierarchy</a></li> </ul> </li> </ul> <h4>上個主題</h4> <p class="topless"><a href="stdtypes.html" title="上一章">4. 內建型態</a></p> <h4>下個主題</h4> <p class="topless"><a href="text.html" title="下一章">6. Text Processing Services</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/3.7/Doc/library/exceptions.rst" rel="nofollow">Show Source </a> </li> </ul> |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |