100.html
来自「Python Ebook Python&XML」· HTML 代码 · 共 45 行
HTML
45 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Developer's Handbook -> Summary</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyN.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="8.html" class="navtitle">Web Development</a> > <a href="0672319942.html" class="navtitle">Python Developer's Handbook</a> > <a href="91.html" class="navtitle">4. Exception Handling</a> > <span class="nonavtitle">Summary</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="99.html" title="The Standard Exception Hierarchy"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=100" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="100.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="101.html" title="Code Examples"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
<a href="5%2F31%2F2002+4%3A32%3A37+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>152015024128143245168232148039199167010047123209178152124239215162147038000015005142037106</font><a href="read0.asp?bookname=0672319942&snode=100&now=5%2F31%2F2002+4%3A32%3A37+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT><h3>Summary</h3>
<p>Python exceptions are mostly used for error handling and event notification. If you don't handle exceptions in your program, Python's interpreter returns traceback messages.</p>
<P>Python comes filled with many built-in exceptions. All these exceptions are part of the <TT Class="monofont">exceptions</TT> module, which is always loaded prior to any program execution.</P>
<P>Exceptions can be handled by using either <tt clASS="monofont">try/except</Tt> or <tt class="monofont">try/finally</tt> statements. The difference between them is that an <tt class="monofont">except</tt> clause is only executed when an exception is raised, and a <tT clAss="monofont">finally</tT> clause is always executed, no matter whether an exception is raised or not. The <tt clAss="monofont">try/finally</tT> statement is good for clean-up actions, but remember that it doesn't actually catch the exceptions.</P>
<P>Python supports both strings and exception classes. As exception classes are grouped within other exception classes (known as base classes), it becomes much easier to catch several different types of errors/exceptions by using just one <Tt claSS="monofont">except</TT> clause. Base classes are never raised, but can be used to catch up errors.</p>
<p>You can either raise your own exceptions or use Python standard exceptions. Python allows you to create your own exceptions by subclassing any standard Python exception.</p>
<p>Exceptions can be raised for several purposes (for example, exit the interpreter, leaving nested loops, and so on). Every time an exception is raised, an instance of the exception class is created.</P>
<P>The <TT clasS="monofont">assert</TT> command helps debug your code by raising a debugging exception.</P>
<p>Besides the <tt class="monofont">exceptions</tt> module, the <tt class="monofont">sys,</tt> the <tT clAss="monofont">errno,</tT> and the <tt clAss="monofont">traceback</tT> modules also offer you some advanced functionality to handle exceptions.</P>
</FOnt>
<P><TABLE width="100%" border=0><TR valign="top"><TD><font size=1 color="#C0C0C0"><br></font></TD><TD align=right><font size=1 color="#C0C0C0">Last updated on 1/30/2002<br>Python Developer's Handbook, © 2002 Sams Publishing</font></TD></TR></TABLE></P>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="99.html" title="The Standard Exception Hierarchy"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=100" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="100.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="101.html" title="Code Examples"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
</TD></TR></TABLE>
<!--EndOfBrowse-->
</TD></TR></TABLE>
<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#990000><tr><td><p align=center><font size=1 face="verdana,arial,helvetica" color=white>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?