comp.lang.ada
 help / color / mirror / Atom feed
From: ahlan@marriott.org
Subject: Re: Last chance handler on a PC
Date: Thu, 30 Jan 2020 11:35:56 -0800 (PST)
Date: 2020-01-30T11:35:56-08:00	[thread overview]
Message-ID: <cf714c35-fdb5-4d9c-bda9-9c0de2df01bd@googlegroups.com> (raw)
In-Reply-To: <c88861f7-b704-4c8e-a065-e22d6888fc17@googlegroups.com>

On Thursday, January 30, 2020 at 9:55:42 AM UTC+1, ah...@marriott.org wrote:
> Hi,
> 
> Does anyone know if it is possible to install a last chance handler for a PC program.
> Ie Write a procedure that gets called when a program issues an unhandled exception
> If it is possible how do you do it?

To answer my own question...
To catch unhandled exceptions you only need to write a simple procedure and export it as __gnat_last_chance_handler.
This is linked into the program in preference to the default last chance handler provided by GNAT.
This procedure is called if nothing catches a raised exception.
Including those raised during package elaboration.

The procedure is not allowed to return so after doing whatever it is you want to do with the exception you must call __gant_unhandled_terminate

The following is an example.

procedure Last_Chance_Handler (Occurrence : Ada.Exceptions.Exception_Occurrence)
  with
    No_Return, Unreferenced, Export,
    Convention    => C,
    External_Name => "__gnat_last_chance_handler";

  procedure Last_Chance_Handler (Occurrence : Ada.Exceptions.Exception_Occurrence) is

    procedure Unhandled_Terminate
    with
      No_Return, Import,
      Convention    => C,
      External_Name => "__gnat_unhandled_terminate";

  begin
    begin
      null;  -- Process the exception here.
    exception
    when others =>
      null;
    end;
    Unhandled_Terminate;
  end Last_Chance_Handler;

  parent reply	other threads:[~2020-01-30 19:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-30  8:55 Last chance handler on a PC ahlan
2020-01-30  9:15 ` J-P. Rosen
2020-01-30  9:17 ` Egil H H
2020-01-30 19:27   ` ahlan
2020-01-31  5:53     ` J-P. Rosen
2020-01-31  7:00       ` Jeffrey R. Carter
2020-01-31  8:51         ` J-P. Rosen
2020-01-30  9:25 ` Dmitry A. Kazakov
2020-01-30 19:10 ` Lucretia
2020-01-30 19:35 ` ahlan [this message]
2020-01-30 20:02   ` Jeffrey R. Carter
2020-01-30 20:26     ` Niklas Holsti
2020-01-30 20:51       ` Jeffrey R. Carter
2020-01-30 21:32         ` Niklas Holsti
2020-01-31 11:12       ` Simon Wright
2020-01-31 11:19         ` Simon Wright
2020-01-31 12:30           ` Niklas Holsti
replies disabled

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