comp.lang.ada
 help / color / mirror / Atom feed
* Exception handling in Ada -> C++ call?
@ 2013-10-18 13:53 kevin.a.peterson
  2013-10-18 14:46 ` Simon Wright
  2013-10-21  7:58 ` Egil H H
  0 siblings, 2 replies; 3+ messages in thread
From: kevin.a.peterson @ 2013-10-18 13:53 UTC (permalink / raw)


Hi, I'm having problems with an Ada program I've been working on. This Ada program makes a call to a C++ library, and the C++ call has a try/catch block. I think my problem boils down to uncaught exceptions hanging on the c++ side hanging the program. This code demonstrates the issue:

Ex.C:
#include <stdexcept>
#include <iostream>
extern "C"
void tester(){
 try{
  throw 1;
 }
 catch(std::logic_error e){
 }
};

testada.adb:
with Ada.Text_Io;
procedure testada is
 procedure TestCpp;
 pragma import(C,TestCpp,"tester");
begin
 Ada.Text_Io.Put_Line("Calling TestCpp");
 TestCpp;
end testada;

When I build this and run testada, I get "terminate called after throwing an instance of 'int'," which I expect, however the application doesn't actually exit but spins a core to 100% usage until I kill it. Also interesting: If I replace the try block with

int x=5/0;

and ignore the compiler warning, the application correctly crashes with SIGFPE, however if I replace the try block with

std::cout << "WHY" << std::endl;
int x=5/0;

I receive "terminate called without an active exception" and the application hangs again until I kill it. Does anyone know the reason for this behaviour? 

I'm currently using GNAT Pro 6.0.2 with GCC 4.1.2 and running on RHEL6, although I've also tried the same program on RHEL5 with earlier GNAT/GCC versions and get the same results. I've also compiled 32 and 64 bit with no difference.

Thanks for the help


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Exception handling in Ada -> C++ call?
  2013-10-18 13:53 Exception handling in Ada -> C++ call? kevin.a.peterson
@ 2013-10-18 14:46 ` Simon Wright
  2013-10-21  7:58 ` Egil H H
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Wright @ 2013-10-18 14:46 UTC (permalink / raw)


kevin.a.peterson@gmail.com writes:

> When I build this and run testada, I get "terminate called after
> throwing an instance of 'int'," which I expect, however the
> application doesn't actually exit but spins a core to 100% usage until
> I kill it. Also interesting: If I replace the try block with

On Mac OS X (ML, Darwin 12.5.0) it doesn't spin: with GCC 4.8.0,

   $ ./testada 
   Calling TestCpp
   terminate called after throwing an instance of 'int'

   raised PROGRAM_ERROR : unhandled signal

and with GNAT GPL 2013,

   $ ./testada 
   Calling TestCpp
   libc++abi.dylib: terminate called throwing an exception

   raised PROGRAM_ERROR : unhandled signal

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Exception handling in Ada -> C++ call?
  2013-10-18 13:53 Exception handling in Ada -> C++ call? kevin.a.peterson
  2013-10-18 14:46 ` Simon Wright
@ 2013-10-21  7:58 ` Egil H H
  1 sibling, 0 replies; 3+ messages in thread
From: Egil H H @ 2013-10-21  7:58 UTC (permalink / raw)


On Friday, October 18, 2013 3:53:27 PM UTC+2, kevin.a....@gmail.com wrote:
> Hi, I'm having problems with an Ada program I've been working on. This Ada 
> program makes a call to a C++ library, and the C++ call has a try/catch block.
> I think my problem boils down to uncaught exceptions hanging on the c++ side
> hanging the program. This code demonstrates the issue:

You may want to take a look at this gem:
http://www.adacore.com/adaanswers/gems/gem-114-ada-and-c-exceptions/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-10-21  7:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-18 13:53 Exception handling in Ada -> C++ call? kevin.a.peterson
2013-10-18 14:46 ` Simon Wright
2013-10-21  7:58 ` Egil H H

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox