Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / html / python / ref / exceptions.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="ref.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="ref.html" title='Python Reference Manual' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="prev" href="naming.html" />
<link rel="parent" href="execmodel.html" />
<link rel="next" href="expressions.html" />
<meta name='aesop' content='information' />
<title>4.2 Exceptions </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="4.1.1 Interaction with dynamic"
href="dynamic-features.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="4. Execution model"
href="execmodel.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="5. Expressions"
href="expressions.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Reference Manual</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><img src='../icons/blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="dynamic-features.html">4.1.1 Interaction with dynamic</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="execmodel.html">4. Execution model</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="expressions.html">5. Expressions</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION006200000000000000000"></A><A NAME="exceptions"></A>
<a id='l2h-321' xml:id='l2h-321'></a>
<BR>
4.2 Exceptions
</H1>
<P>
Exceptions are a means of breaking out of the normal flow of control
of a code block in order to handle errors or other exceptional
conditions. An exception is
<em>raised</em><a id='l2h-324' xml:id='l2h-324'></a> at the point where the error
is detected; it may be <em>handled</em><a id='l2h-325' xml:id='l2h-325'></a> by
the surrounding code block or by any code block that directly or
indirectly invoked the code block where the error occurred.
<a id='l2h-326' xml:id='l2h-326'></a>
<P>
The Python interpreter raises an exception when it detects a run-time
error (such as division by zero). A Python program can also
explicitly raise an exception with the <tt class="keyword">raise</tt> statement.
Exception handlers are specified with the <tt class="keyword">try</tt> ... <tt class="keyword">except</tt>
statement. The <tt class="keyword">try</tt> ... <tt class="keyword">finally</tt> statement
specifies cleanup code which does not handle the exception, but is
executed whether an exception occurred or not in the preceding code.
<P>
Python uses the ``termination''<a id='l2h-327' xml:id='l2h-327'></a> model of
error handling: an exception handler can find out what happened and
continue execution at an outer level, but it cannot repair the cause
of the error and retry the failing operation (except by re-entering
the offending piece of code from the top).
<P>
When an exception is not handled at all, the interpreter terminates
execution of the program, or returns to its interactive main loop. In
either case, it prints a stack backtrace, except when the exception is
<tt class="exception">SystemExit</tt><a id='l2h-323' xml:id='l2h-323'></a>.
<P>
Exceptions are identified by class instances.
Selection of a matching except clause is based on object identity.
The <tt class="keyword">except</tt> clause must reference the same class or a base
class of it.
<P>
When an exception is raised, an object (maybe <code>None</code>) is passed
as the exception's <em>value</em>; this object does not affect the
selection of an exception handler, but is passed to the selected
exception handler as additional information. For class exceptions,
this object must be an instance of the exception class being raised.
<P>
<div class="warning"><b class="label">Warning:</b>
Messages to exceptions are not part of the Python API. Their contents may
change from one version of Python to the next without warning and should not
be relied on by code which will run under multiple versions of the
interpreter.
</div>
<P>
See also the description of the <tt class="keyword">try</tt> statement in
section&nbsp;<A href="try.html#try">7.4</A> and <tt class="keyword">raise</tt> statement in
section&nbsp;<A href="raise.html#raise">6.9</A>.
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="4.1.1 Interaction with dynamic"
href="dynamic-features.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="4. Execution model"
href="execmodel.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="5. Expressions"
href="expressions.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Reference Manual</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><img src='../icons/blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="dynamic-features.html">4.1.1 Interaction with dynamic</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="execmodel.html">4. Execution model</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="expressions.html">5. Expressions</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>