<!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>format_exception — Astropy v0.2.4</title> <link rel="stylesheet" href="../_static/bootstrap-astropy.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '0.2.4', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </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/sidebar.js"></script> <link rel="shortcut icon" href="../_static/astropy_logo.ico"/> <link rel="top" title="Astropy v0.2.4" href="../index.html" /> <link rel="up" title="Astropy Core Package Utilities (astropy.utils)" href="../utils/index.html" /> <link rel="next" title="is_path_hidden" href="astropy.utils.misc.is_path_hidden.html" /> <link rel="prev" title="silence" href="astropy.utils.misc.silence.html" /> </head> <body> <div class="topbar"> <a class="brand" title="Documentation Home" href="../index.html"></a> <ul> <li><a class="homelink" title="AstroPy Homepage" href="http://www.astropy.org"></a></li> <li><a title="General Index" href="../genindex.html">Index</a></li> <li><a title="Python Module Index" href="../py-modindex.html">Modules</a></li> <li> <form action="../search.html" method="get"> <input type="text" name="q" placeholder="Search" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </li> </ul> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right"> <a href="astropy.utils.misc.is_path_hidden.html" title="is_path_hidden"> next » </a> </li> <li class="right"> <a href="astropy.utils.misc.silence.html" title="silence"> « previous </a> | </li> <li> <a href="../index.html">Astropy v0.2.4</a> » </li> <li><a href="../utils/index.html" accesskey="U">Astropy Core Package Utilities (<tt class="docutils literal"><span class="pre">astropy.utils</span></tt>)</a> »</li> <li>format_exception</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="format-exception"> <h1>format_exception<a class="headerlink" href="#format-exception" title="Permalink to this headline">¶</a></h1> <dl class="function"> <dt id="astropy.utils.misc.format_exception"> <tt class="descclassname">astropy.utils.misc.</tt><tt class="descname">format_exception</tt><big>(</big><em>msg</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="reference external" href="http://github.com/astropy/astropy/tree/v0.2.4/astropy/utils/misc.py#L501" title="Push the Edit button on the next page"><span class="edit-on-github viewcode-link"> [edit on github]</span></a><a class="reference internal" href="../_modules/astropy/utils/misc.html#format_exception"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#astropy.utils.misc.format_exception" title="Permalink to this definition">¶</a></dt> <dd><p>Given an exception message string, uses new-style formatting arguments <tt class="docutils literal"><span class="pre">{filename}</span></tt>, <tt class="docutils literal"><span class="pre">{lineno}</span></tt>, <tt class="docutils literal"><span class="pre">{func}</span></tt> and/or <tt class="docutils literal"><span class="pre">{text}</span></tt> to fill in information about the exception that occurred. For example:</p> <blockquote> <div><dl class="docutils"> <dt>try:</dt> <dd>1/0</dd> <dt>except:</dt> <dd><dl class="first last docutils"> <dt>raise ZeroDivisionError(</dt> <dd><dl class="first last docutils"> <dt>format_except(‘A divide by zero occurred in {filename} at ‘</dt> <dd>‘line {lineno} of function {func}.’))</dd> </dl> </dd> </dl> </dd> </dl> </div></blockquote> <p>Any additional positional or keyword arguments passed to this function are also used to format the message.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">This uses <tt class="xref py py-obj docutils literal"><span class="pre">sys.exc_info</span></tt> to gather up the information needed to fill in the formatting arguments. Python 2.x and 3.x have slightly different behavior regarding <tt class="xref py py-obj docutils literal"><span class="pre">sys.exc_info</span></tt> (the latter will not carry it outside a handled exception), so it’s not wise to use this outside of an <tt class="xref py py-obj docutils literal"><span class="pre">except</span></tt> clause - if it is, this will substitute ‘<unkown>’ for the 4 formatting arguments.</p> </div> </dd></dl> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"><h3>Page Contents</h3> <ul> <li><a class="reference internal" href="#">format_exception</a></li> </ul> </div> </div> <div class="clearer"></div> </div> <footer class="footer"> <p class="pull-right"> <a href="../_sources/_generated/astropy.utils.misc.format_exception.txt" rel="nofollow">Page Source</a> <a href="#">Back to Top</a></p> <p> © Copyright 2011-2013, The Astropy Developers.<br/> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. Last built 22 Oct 2013. <br/> </p> </footer> </body> </html>