comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Discriminants or Constructor Function for Limited Types
Date: Sun, 8 May 2022 20:00:15 +0200	[thread overview]
Message-ID: <t590fe$3ef$1@gioia.aioe.org> (raw)
In-Reply-To: 7puf7h59k2e2ns66918i95s847na2b8num@4ax.com

On 2022-05-08 19:19, Doctor Who wrote:
> On Sun, 8 May 2022 10:37:48 +0200, "Dmitry A. Kazakov"

>> Note, that your code is already unsafe because nobody knows if
>> Create_or_Open_Output always opens the file and because there is no
>> guarantee that the file is closed, while the design
>>
>>     declare
>>        Output_File : Some_File_Type;
>>     begin
>>        Write_Output (Output_File, Data);
>>     end;
>>
>> is 100% safe.
> 
> Not in the case that your data space is exhausted, in that case
> Write_Output will fail, because you have no checks of free space
> before writing.

Upon a write error an exception will propagate and Output_File will go 
out of the scope. The file will be closed and the exception will 
continue its way. This is a safe behavior. Randy's code is unsafe and 
requires catching and re-raising I/O exceptions in the client code.

This is an illustration why exceptions should be allowed to propagate 
out of Finalize. When Finalize is used to close a handle this may fail 
and there is no way to retry inside Finalize. The choice in Ada is 
between aborting the program or sweeping the problem under the rug 
ignoring the problem. A more sane approach would be to propagate 
exception out of Finalize indicating the problem.

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

  reply	other threads:[~2022-05-08 18:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-04  9:02 Discriminants or Constructor Function for Limited Types R R
2022-05-04  9:40 ` Jeffrey R.Carter
2022-05-04  9:47 ` Dmitry A. Kazakov
2022-05-04 23:49   ` Randy Brukardt
2022-05-05  6:56     ` Dmitry A. Kazakov
2022-05-06  1:53       ` Randy Brukardt
2022-05-06  8:48         ` Dmitry A. Kazakov
2022-05-07  3:26           ` Randy Brukardt
2022-05-07 14:55             ` Dmitry A. Kazakov
2022-05-08  2:32               ` Randy Brukardt
2022-05-08  8:37                 ` Dmitry A. Kazakov
2022-05-08 17:19                   ` Doctor Who
2022-05-08 18:00                     ` Dmitry A. Kazakov [this message]
2022-05-08 18:07                       ` Doctor Who
2022-05-09  8:52                       ` Niklas Holsti
2022-05-09  9:45                         ` Dmitry A. Kazakov
2022-05-09 10:19                       ` Doctor Who
2022-05-09 11:15                         ` Dmitry A. Kazakov
2022-05-09 12:05                           ` Doctor Who
2022-05-09 12:31                             ` Dmitry A. Kazakov
2022-05-10  4:48                   ` Randy Brukardt
2022-05-10  6:18                     ` Dmitry A. Kazakov
2022-05-04 15:05 ` AdaMagica
2022-05-05  9:59 ` R R
replies disabled

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