From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!aioe.org!siG8trSPtxwtkBCOZpBn8A.user.46.165.242.91.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Extra information in the message string of exceptions. Date: Mon, 6 Jun 2022 21:24:27 +0200 Organization: Aioe.org NNTP Server Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="7486"; posting-host="siG8trSPtxwtkBCOZpBn8A.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader02.eternal-september.org comp.lang.ada:63935 List-Id: 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