mirror of
https://github.com/boostorg/python.git
synced 2026-01-23 05:42:30 +00:00
61 lines
3.1 KiB
HTML
61 lines
3.1 KiB
HTML
<html>
|
|
<head>
|
|
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
|
|
<title>Exception Translation</title>
|
|
<link rel="stylesheet" href="theme/style.css" type="text/css">
|
|
<link rel="prev" href="iterators.html">
|
|
</head>
|
|
<body>
|
|
<table width="100%" height="48" border="0" cellspacing="2">
|
|
<tr>
|
|
<td><img src="theme/c%2B%2Bboost.gif">
|
|
</td>
|
|
<td width="85%">
|
|
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Exception Translation</b></font>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
<table border="0">
|
|
<tr>
|
|
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
|
<td width="30"><a href="iterators.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
|
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
|
|
</tr>
|
|
</table>
|
|
<p>
|
|
All C++ exceptions must be caught at the boundary with Python code. This
|
|
boundary is the point where C++ meets Python. Boost.Python provides a
|
|
default exception handler that translates selected standard exceptions,
|
|
then gives up:</p>
|
|
<code><pre>
|
|
<span class=identifier>raise </span><span class=identifier>RuntimeError</span><span class=special>, </span><span class=literal>'unidentifiable C++ Exception'
|
|
</span></pre></code>
|
|
<p>
|
|
Users may provide custom translation. Here's an example:</p>
|
|
<code><pre>
|
|
<span class=keyword>struct </span><span class=identifier>PodBayDoorException</span><span class=special>;
|
|
</span><span class=keyword>void </span><span class=identifier>translator</span><span class=special>(</span><span class=identifier>PodBayDoorException</span><span class=special>& </span><span class=identifier>x</span><span class=special>) </span><span class=special>{
|
|
</span><span class=identifier>PyErr_SetString</span><span class=special>(</span><span class=identifier>PyExc_UserWarning</span><span class=special>, </span><span class=string>"I'm sorry Dave..."</span><span class=special>);
|
|
</span><span class=special>}
|
|
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>kubrick</span><span class=special>) </span><span class=special>{
|
|
</span><span class=identifier>register_exception_translator</span><span class=special><
|
|
</span><span class=identifier>PodBayDoorException</span><span class=special>>(</span><span class=identifier>translator</span><span class=special>);
|
|
</span><span class=special>...
|
|
</span></pre></code>
|
|
<table border="0">
|
|
<tr>
|
|
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
|
|
<td width="30"><a href="iterators.html"><img src="theme/l_arr.gif" border="0"></a></td>
|
|
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
<hr size="1"><p class="copyright">Copyright © 2002 David Abrahams<br>Copyright © 2002 Joel de Guzman<br><br>
|
|
<font size="2">Permission to copy, use, modify, sell and distribute this document
|
|
is granted provided this copyright notice appears in all copies. This document
|
|
is provided "as is" without express or implied warranty, and with
|
|
no claim as to its suitability for any purpose. </font> </p>
|
|
</body>
|
|
</html>
|