comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Discriminants or Constructor Function for Limited Types
Date: Mon, 9 May 2022 11:52:37 +0300	[thread overview]
Message-ID: <jds32mF89prU1@mid.individual.net> (raw)
In-Reply-To: <t590fe$3ef$1@gioia.aioe.org>

On 2022-05-08 21:00, Dmitry A. Kazakov wrote:
> 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.


That might work if the scope that is being left has only one local 
object that needs finalization. But what if there are several, and the 
first Finalize propagates an expection? Should the remaining 
finalizations be skipped? That would not be right. But if the remaining 
finalizations are also attempted, their execution may run into problems 
because the first Finalize was not completed. Moreover, the remaining 
finalizations might also propagate one or more exceptions, so now there 
could be a whole set of different exception instances being propagated 
from all these finalizations. Which exception(s) should be retained and 
handled?

The term "can of worms" comes to mind...

  parent reply	other threads:[~2022-05-09  8:52 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
2022-05-08 18:07                       ` Doctor Who
2022-05-09  8:52                       ` Niklas Holsti [this message]
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