comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Extra information in the message string of exceptions.
Date: Mon, 6 Jun 2022 21:24:27 +0200	[thread overview]
Message-ID: <t7lk9a$79u$1@gioia.aioe.org> (raw)
In-Reply-To: t7lhnq$eeh$1@dont-email.me

On 2022-06-06 20:40, G.B. wrote:
> On 06.06.22 15:40, Fabien Chouteau wrote:
>> On Monday, June 6, 2022 at 3:02:25 PM UTC+2, roda...@gmail.com wrote:
>>> For instance, a Constraint_Error message might provide details on
>>> the variable name, the legal range and the erroneous value which caused
>>> the exception.
>>
>> That's a really good idea I would say. Extremely useful during 
>> development where I often start the debugger just to know what value 
>> triggered a Constraint_Error.
>>
>> I guess the drawback is performance as formatting string with extra 
>> information will have a cost.
>> But this feature could be activated with a switch only when needed.
> 
> Will it help to have a standard object taking just the data?

Besides problems with finalization and touching memory pools, an 
exception from a rendezvous is propagated in two tasks. Will the object 
be shared, copied?

------------------
Though you can always serialize an object into a string stream and use 
the result. One could consider some syntax sugar like:

    raise E with X;

would mean

    declare
       S : aliased String_Stream (200);
    begin
       T'Output (S'Access, X); -- T is the subtype of X
       raise E with S.Get;
    end;

and

    function Stream (X : Exception_Occurrence)
       return not null access Root_Stream_Type'Class;

So, in the handler:

    when Error : E =>
       declare
          X : T'Class := T'Class'Input (Error'Stream);
       begin
          ...
       end;

without the sugar:

    when Error : E =>
       declare
          S : aliased String_Stream (200);
       begin
          S.Set (Exception_Message (S));
          declare
             X : T'Class := T'Class'Input (S'Access);
          begin
             ...
          end;
       end;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2022-06-06 19:24 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-06 12:59 Extra information in the message string of exceptions Rod Kay
2022-06-06 13:40 ` Fabien Chouteau
2022-06-06 18:40   ` G.B.
2022-06-06 19:24     ` Dmitry A. Kazakov [this message]
2022-06-07 11:26   ` Rod Kay
2022-06-07 15:55   ` Fabien Chouteau
2022-06-07 16:41     ` Anh Vo
2022-06-08  7:31     ` Jerry
2022-06-08  8:04       ` Dmitry A. Kazakov
2022-06-09  2:39         ` Jerry
2022-06-08  9:08       ` Dmitry A. Kazakov
2022-10-27 11:56         ` Rod Kay
2022-10-29  0:35           ` Jerry
2022-10-29  3:10             ` Rod Kay
2022-10-29  6:30               ` Gautier write-only address
2022-10-29  8:59               ` G.B.
2022-11-01  0:05             ` Jerry
2022-06-06 14:31 ` Gautier write-only address
2022-06-07  2:33   ` Randy Brukardt
2022-06-07 11:47     ` Rod Kay
2022-06-07 11:29   ` Rod Kay
2022-06-06 20:14 ` Luke A. Guest
2022-06-07 11:51   ` Rod Kay
2022-06-07 21:06     ` Luke A. Guest
2022-06-06 20:49 ` DrPi
2022-06-06 23:17   ` Jerry
2022-06-07  1:53     ` Gautier write-only address
2022-06-07  2:35       ` Randy Brukardt
2022-06-07  8:07       ` Simon Wright
2022-06-08  7:14       ` Jerry
2022-06-09  8:21 ` Robin Vowels
replies disabled

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