<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2011:07:07</title>
        <description></description>
        <link>https://baszerr.eu/</link>
        <lastBuildDate>Fri, 03 Apr 2026 22:36:47 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://baszerr.eu/</link>
        </image>
        <item>
            <title>1</title>
            <link>https://baszerr.eu/doku.php?id=blog:2011:07:07:1</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;poker_face&quot;&gt;2011.07.07 - poker face&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
a friend of mine sent me excellent link recently. having the same feeling when watching non-technical ppl using their computers in… let us say… suboptimal manner?
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2011%3A07%3A07%3A1&amp;amp;media=humour:poker_face.jpeg&quot; class=&quot;media&quot; title=&quot;humour:poker_face.jpeg&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?media=humour:poker_face.jpeg&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; title=&quot;poker face&quot; alt=&quot;poker face&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:09:36 +0000</pubDate>
        </item>
        <item>
            <title>2</title>
            <link>https://baszerr.eu/doku.php?id=blog:2011:07:07:2</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;pyerr_print&quot;&gt;2011.07.07 - PyErr_Print()&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;https://en.wikipedia.org/wiki/Python_(programming_language)&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Python_(programming_language)&quot;&gt;Python&lt;/a&gt; is known to cope well with &lt;a href=&quot;https://en.wikipedia.org/wiki/C_(programming_language)&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/C_(programming_language)&quot;&gt;C&lt;/a&gt; via &lt;a href=&quot;http://docs.python.org/c-api&quot; class=&quot;urlextern&quot; title=&quot;http://docs.python.org/c-api&quot; rel=&quot;ugc nofollow&quot;&gt;PythonC&lt;/a&gt;. thanks to &lt;a href=&quot;http://www.boost.org/doc/libs/release/libs/python/doc&quot; class=&quot;urlextern&quot; title=&quot;http://www.boost.org/doc/libs/release/libs/python/doc&quot; rel=&quot;ugc nofollow&quot;&gt;boost::python&lt;/a&gt; it integrates well with &lt;a href=&quot;https://en.wikipedia.org/wiki/C++&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/C++&quot;&gt;C++&lt;/a&gt; as well.
&lt;/p&gt;

&lt;p&gt;
this is theory. and we all know that in theory there is no difference between theory and practice but in practice there is.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;2011.07.07 - PyErr_Print()&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;pyerr_print&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-445&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;how_it_started&quot;&gt;how it started&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
it is not that bad actually, as long as you call C++ code from the inside of the Pyhton script. recently my need was to embed Python code to the C++ sources. while coding new component for &lt;a href=&quot;http://www.acarm.wcss.wroc.pl&quot; class=&quot;urlextern&quot; title=&quot;http://www.acarm.wcss.wroc.pl&quot; rel=&quot;ugc nofollow&quot;&gt;ACARM-ng&lt;/a&gt; project, that is going to be a code base for user plugins, written in Python, instead of C++ i started using boost::python to make things simpler&lt;sup&gt;&lt;a href=&quot;#fn__1&quot; id=&quot;fnt__1&quot; class=&quot;fn_top&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt;. then few new, interesting things came up. when my “hello (python) world” (a sort of prototype; PoC-alike code) started to work as i expected i created new component (named PythonAPI) and straight away came across an issue. how to solve exceptions thrown in Python code? i mean both user-generated and syntax error, since both of them may (and will) appear in real-life code, written by an end user.
&lt;/p&gt;

&lt;p&gt;
how it worked in PoC? take a look at the following (simplified) example:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;  try
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    PyImport_AppendInittab&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;mymod&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; PyInit_mymod&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    Py_Initialize&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    object mainModule&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;import&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;__main__&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    object mainNamespace&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;mainModule.&lt;span class=&quot;me1&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;__dict__&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    exec_file&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;some_script.py&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; mainNamespace&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  catch&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; boost&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;python&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;error_already_set&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    PyErr_Print&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
when error is risen it is reported in C++ code as an exception of type &lt;em&gt;boost::python::error_already_set&lt;/em&gt;, which does not mean anything more than “exception has been thrown in Python”. the funny thing is that it does not have any information on exception details. looks shitty straight away, but ok - let&amp;#039;s see how to extract error report.
&lt;/p&gt;

&lt;p&gt;
PythonC has ready-to-use call to print error message directly on the screen, namely &lt;em&gt;PyErr_Print()&lt;/em&gt;. nice feature - good for testing. used in my PoC as well. but how to do this in final code? ACARM-ng is a daemon by-design, thus writing anything on the screen does not make any sense. logging mechanism has to be used for that. but how the hell get error string?!
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;how it started&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;how_it_started&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;446-2411&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;the_re_search&quot;&gt;the (re)search&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
i&amp;#039;ve done a lot of goolging, searching forums, reading APIs, etc… this question/problem appears to be quite common on the net, though usable solution is hard to find, not mentioning - to self develop it, when you&amp;#039;re new to both APIs having only basic knowledge and experience with Python.
&lt;/p&gt;

&lt;p&gt;
while looking the net i came mostly across not answered topics and “interesting” solutions/code-monsters like &lt;a href=&quot;http://objectmix.com/python/317969-how-get-string-printed-pyerr_print.html&quot; class=&quot;urlextern&quot; title=&quot;http://objectmix.com/python/317969-how-get-string-printed-pyerr_print.html&quot; rel=&quot;ugc nofollow&quot;&gt;replacing error stream with a string and reading from it&lt;/a&gt;! not only that i have to keep WHOLE stderr in some string (what for?! beside script author may want to use printf-like debugging, that i may interfere with this way) and then “guess” where is my error message. the solution is merely an UGLY HACK.
&lt;/p&gt;

&lt;p&gt;
i was so desperate it was thinking about ripping &lt;em&gt;PyErr_Print()&lt;/em&gt; call from the APIs sources and switching low-level calls that print on the screen. i even though about taking user script into one, big try-catch and saving error as some “magic” variable (imagine the state of mind when such a concepts can arose!).
&lt;/p&gt;

&lt;p&gt;
luckily for me my holidays time had come and i could leave this topic for a while…
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;the (re)search&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;the_re_search&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;2412-3629&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;solution&quot;&gt;solution&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
few days ago i came back to work and after doing all tasks that have gathered over a time, i came back to the topic. this time i was far more lucky. i found excellent blog entry on this issue. &lt;a href=&quot;http://thejosephturner.com/blog&quot; class=&quot;urlextern&quot; title=&quot;http://thejosephturner.com/blog&quot; rel=&quot;ugc nofollow&quot;&gt;Joseph Turner&lt;/a&gt; gave the working code example of possible solution in his &lt;a href=&quot;http://thejosephturner.com/blog/2011/06/15/embedding-python-in-c-applications-with-boostpython-part-2&quot; class=&quot;urlextern&quot; title=&quot;http://thejosephturner.com/blog/2011/06/15/embedding-python-in-c-applications-with-boostpython-part-2&quot; rel=&quot;ugc nofollow&quot;&gt;embedding Python in C++ with boost::python, part 2&lt;/a&gt; article.
&lt;/p&gt;

&lt;p&gt;
this PoC of exception data extraction worked as a charm! what i did was to wrap this in a class and add some common functionalities, that are useful in this context. current (not final though) implementation is now part of &lt;a href=&quot;http://www.acarm.wcss.wroc.pl&quot; class=&quot;urlextern&quot; title=&quot;http://www.acarm.wcss.wroc.pl&quot; rel=&quot;ugc nofollow&quot;&gt;ACARM-ng&amp;#039;s&lt;/a&gt; code, namely the &lt;a href=&quot;http://repo.acarm.wcss.wroc.pl/main&quot; class=&quot;urlextern&quot; title=&quot;http://repo.acarm.wcss.wroc.pl/main&quot; rel=&quot;ugc nofollow&quot;&gt;development branch&lt;/a&gt;, as GPLv2 sources. as of writing these words it is only available through &lt;a href=&quot;http://repo.acarm.wcss.wroc.pl/devel/basz&quot; class=&quot;urlextern&quot; title=&quot;http://repo.acarm.wcss.wroc.pl/devel/basz&quot; rel=&quot;ugc nofollow&quot;&gt;my development branch&lt;/a&gt;, since whole module is not done (i.e. fully functional) yet.
&lt;/p&gt;

&lt;p&gt;
the class&amp;#039; draft looks like this
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;string&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;stdexcept&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;boost/python.hpp&amp;gt;&lt;/span&gt;
&amp;nbsp;
using namespace std&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
namespace py&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;boost&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;python&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
class ExceptionHandle
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
public&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;
  ExceptionHandle&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;
    type_&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;???&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
    msg_&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;???&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
    backtrace_&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;???&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;co1&quot;&gt;// maby there was no exception at all?&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; PyErr_Occurred&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt;NULL &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      throw std&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;runtime_error&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;no exception reported by Python&#039;s interpreter&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;co1&quot;&gt;// read exception-related data from python&lt;/span&gt;
    PyObject &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;typePtr     &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    PyObject &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;valuePtr    &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    PyObject &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;backtracePtr&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    PyErr_Fetch&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;typePtr&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;valuePtr&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;backtracePtr&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;co1&quot;&gt;// check if type is set&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;typePtr&lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt;NULL&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;        h&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;typePtr&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;str&lt;/span&gt;             pyStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;h&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;extract&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;string&lt;span class=&quot;sy0&quot;&gt;&amp;gt;&lt;/span&gt; extrPyStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;pyStr&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; extrPyStr.&lt;span class=&quot;me1&quot;&gt;check&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
        type_&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;extrPyStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span class=&quot;co1&quot;&gt;// check if message is set&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;valuePtr&lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt;NULL&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;        h&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;valuePtr&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;str&lt;/span&gt;             pyStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;h&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;extract&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;string&lt;span class=&quot;sy0&quot;&gt;&amp;gt;&lt;/span&gt; extrPyStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;pyStr&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; extrPyStr.&lt;span class=&quot;me1&quot;&gt;check&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
        msg_&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;extrPyStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span class=&quot;co1&quot;&gt;// check if backtrace is set&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;backtracePtr&lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt;NULL&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;        h&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;backtracePtr&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;object&lt;/span&gt;          tb&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;traceback&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;object&lt;/span&gt;          formatTb&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; tb.&lt;span class=&quot;me1&quot;&gt;attr&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;format_tb&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;object&lt;/span&gt;          tbList&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; formatTb&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;h&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;object&lt;/span&gt;          tbStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;tbList&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      py&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;extract&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;string&lt;span class=&quot;sy0&quot;&gt;&amp;gt;&lt;/span&gt; extrPyStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;tbStr&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; extrPyStr.&lt;span class=&quot;me1&quot;&gt;check&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
        backtrace_&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;extrPyStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;co1&quot;&gt;// ok - this one has been read&lt;/span&gt;
    clearState&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; rethrow&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    throw std&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;runtime_error&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; str&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  std&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;string&lt;/span&gt; str&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; getType&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;: &amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;getMessage&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;; backtrace is:&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;getBacktraceStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; std&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;getType&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; type_&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; std&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;getMessage&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; msg_&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;co1&quot;&gt;// NOTE: backtrace should be also available as an vector of stack entries&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; std&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;getBacktraceStr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; backtrace_&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;kw4&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; clearState&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    PyErr_Clear&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
private&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;
  std&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;string&lt;/span&gt; type_&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  std&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;string&lt;/span&gt; msg_&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  std&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;string&lt;/span&gt; backtrace_&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// class ExceptionHandle&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
compilable sources, along with all dependencies can be downloaded from &lt;a href=&quot;http://repo.acarm.wcss.wroc.pl/devel/basz/src/pythonapi/PythonAPI&quot; class=&quot;urlextern&quot; title=&quot;http://repo.acarm.wcss.wroc.pl/devel/basz/src/pythonapi/PythonAPI&quot; rel=&quot;ugc nofollow&quot;&gt;PythonAPI on my development branch&lt;/a&gt;&lt;sup&gt;&lt;a href=&quot;#fn__2&quot; id=&quot;fnt__2&quot; class=&quot;fn_top&quot;&gt;2)&lt;/a&gt;&lt;/sup&gt;.
&lt;/p&gt;

&lt;p&gt;
hope this will save you hours and nerves.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;solution&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;solution&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;3630-&amp;quot;} --&gt;&lt;div class=&quot;footnotes&quot;&gt;
&lt;div class=&quot;fn&quot;&gt;&lt;sup&gt;&lt;a href=&quot;#fnt__1&quot; id=&quot;fn__1&quot; class=&quot;fn_bot&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt; 
&lt;div class=&quot;content&quot;&gt;PythonC looks awful to me…&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;fn&quot;&gt;&lt;sup&gt;&lt;a href=&quot;#fnt__2&quot; id=&quot;fn__2&quot; class=&quot;fn_bot&quot;&gt;2)&lt;/a&gt;&lt;/sup&gt; 
&lt;div class=&quot;content&quot;&gt;will soon be available on main branch and next ACARM-ng&amp;#039;s release&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:09:36 +0000</pubDate>
        </item>
    </channel>
</rss>
