title: how to get Ada exception message when catching from C++ handler?
body: <p>Using GNAT Ada and Gnu C++, I'm interfacing an Ada piece of code with a c++ wrapper and I'd like to catch Ada exceptions properly when running this (stupid) code:</p>
  
  <pre><code>with ada.text_io;
  
  package body ada_throw is
  
     procedure ada_throw is
     begin
        ada.text_io.put_line ("hello");
        raise program_error;
     end ada_throw;       
  
  end ada_throw;
  </code></pre>
  
  <p>relevant spec code is:</p>
  
  <pre><code>package ada_throw is
  
     procedure ada_throw;
     pragma export (convention =&gt; C, entity =&gt; ada_throw, external_name =&gt; "ada_throw");
  
  end ada_throw;
  </code></pre>
  
  <p>Whe doing this on the C++ side:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  extern "C"
  {
    void ada_throw();
    void adainit();
  }
  
  int main()
  {
    adainit();
    ada_throw();
    std::cout &lt;&lt; "end of program" &lt;&lt; std::endl;
    return 0;
  }
  </code></pre>
  
  <p>I'm getting this:</p>
  
  <pre><code>hello
  
  raised PROGRAM_ERROR : ada_throw.adb:8 explicit raise
  </code></pre>
  
  <p>So the exception mechanism works, I don't get the last print of my C++ program and the return code is non-zero.</p>
  
  <p>Now I want to <em>catch</em> the exception. If I use <code>catch(...)</code> it works, but I can't get the explicit error message anymore, so I tried this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cxxabi.h&gt;
  extern "C"
  {
    void ada_throw();
    void adainit();
  }
  
  int main()
  {
    adainit();
  
    try
    {
      ada_throw();
    }
    catch (abi::__foreign_exception const &amp;e)
    {
      std::cout &lt;&lt; "exception" &lt;&lt; std::endl;        
    }
  
    std::cout &lt;&lt; "end of program" &lt;&lt; std::endl;
    return 0;
  }
  </code></pre>
  
  <p>it works properly, I get:</p>
  
  <pre><code>hello
  exception
  end of program
  </code></pre>
  
  <p>The only catch is that <code>abi::__foreign_exception</code> doesn't have a <code>what()</code> method, so I cannot get hold of the meaningful error message.</p>
  
  <p>And debugging the program to try to hack into <code>e</code> is also a dead end since it's just a null pointer with the proper type:</p>
  
  <pre><code>(gdb) p &amp;e
  $2 = (const __cxxabiv1::__foreign_exception *) 0x0
  </code></pre>
  
  <p>Is there a way to get it from the C++ ?</p>