This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Imported C++ exceptions


It is now possible to import C++ exceptions and to handle it.
The following program will display: Got Cpp exception
It can be built using the following project file:

project except is
  for Languages use ("Ada", "C++");
  for Main use ("main.adb");
end except;

package Cppexcept is
   Cpp_Int_Exception : exception;
   pragma Import (Cpp, Cpp_Int_Exception, "_ZTIi");
end Cppexcept;

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Exceptions; use Ada.Exceptions;
with Cppexcept; use Cppexcept;

procedure Main is
   procedure Raise_Excep_Int;
   pragma Import (C, Raise_Excep_Int);
   --  Raise a Cpp exception
begin
   Raise_Excep_Int;
exception
   when Cpp_Int_Exception =>
      Put_Line ("Got Cpp exception");
   when X: others =>
      Put_Line ("Err, got unexpected exception: "
                & Exception_Information (X));
end Main;

extern "C" void raise_excep_int (void)
{
  throw 2;
}

Tested on x86_64-pc-linux-gnu, committed on trunk

2013-10-14  Tristan Gingold  <gingold@adacore.com>

	* sem_prag.adb (Process_Import_Or_Interface): Allow importing
	of exception using convention Cpp.
	* exp_prag.adb (Expand_Pragma_Import_Or_Interface): Expand cpp
	imported exceptions.
	* raise-gcc.c (is_handled_by): Filter C++ exception occurrences.
	* gnat_rm.texi: Document how to import C++ exceptions.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]