From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a37:bf82:: with SMTP id p124mr7024472qkf.337.1580412957334; Thu, 30 Jan 2020 11:35:57 -0800 (PST) X-Received: by 2002:a9d:12f1:: with SMTP id g104mr4569298otg.149.1580412956935; Thu, 30 Jan 2020 11:35:56 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 30 Jan 2020 11:35:56 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=2a02:120b:2c67:3370:d4be:c3ef:62:9e6e; posting-account=DQbqYQoAAACn8hHn2LmG2aF7Mhbxl_Lf NNTP-Posting-Host: 2a02:120b:2c67:3370:d4be:c3ef:62:9e6e References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Last chance handler on a PC From: ahlan@marriott.org Injection-Date: Thu, 30 Jan 2020 19:35:57 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:57990 Date: 2020-01-30T11:35:56-08:00 List-Id: 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;