Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

It's ten o'clock; do you know where your processes are?


devel / comp.lang.ada / Variable value if exception is raised

SubjectAuthor
* Variable value if exception is raisednytpu
`- Re: Variable value if exception is raisedJeffrey R.Carter

1
Variable value if exception is raised

<tldq4n$3i1p2$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9040&group=comp.lang.ada#9040

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: alex@nytpu.com (nytpu)
Newsgroups: comp.lang.ada
Subject: Variable value if exception is raised
Date: Sun, 20 Nov 2022 18:03:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <tldq4n$3i1p2$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 20 Nov 2022 18:03:04 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="1ab5ff3814d029bf4725b1936f1deaac";
logging-data="3737378"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Bt194B227yuIG0xIfG/q9"
User-Agent: Pan/0.150 (Moucherotte; d13562f /home/alex/aur/pan-git/pan)
Cancel-Lock: sha1:qj6LD/NCmdpWQE5YMPP/3l05XCI=
 by: nytpu - Sun, 20 Nov 2022 18:03 UTC

Hello everyone,

If an exception is *explicitly* raised during a variable assignment, what
happens to the variable contents? Are they in an undefined ("abnormal")
state, or are the previous contents preserved?

For example:
```
with Ada.Text_IO;
procedure Test is
function Always_Raises return Integer is
begin
raise Program_Error;
return 1;
end Always_Raises;

I : Integer := 0;
begin
-- insert a nested handler, because the ARM § 11.4 ¶ 3 *does*
-- say that the currently executing body is "abnormally
-- completed" (including finalizing everything) before
-- entering the exception handler
begin
I := Always_Raises;
exception
when others => null;
end;
Ada.Text_IO.Put_Line(Integer'Image(I));
end;
```
What, if anything, will be printed? (Disclaimer: I know the preexisting
variable value will be preserved in GNAT specifically, but I'm asking if
the standard guarantees that's the case)

I read through the ARM 2012 § 11 and § 5.2, as well as skimming through
everything related to “assignment” and “exceptions” in the ARM index;
and didn't see much relating to this. All I saw is this:
> When an exception occurrence is raised by the execution of a given
> construct, the rest of the execution of that construct is abandoned
— ARM 2012 § 11.4 ¶ 3
Which I guess implicitly protects variable values since assigning to a
variable is performed after evaluating the right hand side, but still not
necessarily a clear answer.

I did see in § 13.9.1 that language-defined validity checks (e.g. bounds
checks) failing or calling `abort` in a task during an assignment will
cause the variable to enter an "abnormal" (i.e. invalid) state, but that
doesn't cover user-raised exceptions.

--
~nytpu

Re: Variable value if exception is raised

<tldtgh$3ig2s$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9041&group=comp.lang.ada#9041

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: Variable value if exception is raised
Date: Sun, 20 Nov 2022 20:00:32 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <tldtgh$3ig2s$1@dont-email.me>
References: <tldq4n$3i1p2$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 20 Nov 2022 19:00:33 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="f2ae079dae55ba6daa03ced8584b99bc";
logging-data="3752028"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Mmzi7YCIHRKJRWgrRbNiD7UNfv5S4iPQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:ONFIPnP484gCWrUjsPSSRtMNoA8=
In-Reply-To: <tldq4n$3i1p2$1@dont-email.me>
Content-Language: en-US
 by: Jeffrey R.Carter - Sun, 20 Nov 2022 19:00 UTC

On 2022-11-20 19:03, nytpu wrote:
>
> If an exception is *explicitly* raised during a variable assignment, what
> happens to the variable contents? Are they in an undefined ("abnormal")
> state, or are the previous contents preserved?

If the exception occurs during evaluation of the RHS, as in your example, then
the language guarantees that the value of the LHS is unchanged. The execution of
the assignment statement is abandoned before the value of the LHS is changed.

If an exception is raised while adjusting a controlled LHS, then the value of
the LHS has already been changed before the exception is raised.

> -- insert a nested handler, because the ARM § 11.4 ¶ 3 *does*
> -- say that the currently executing body is "abnormally
> -- completed" (including finalizing everything) before
> -- entering the exception handler

This comment is false. Finalization does not occur until the exception handler
finishes. Exception handlers would be pretty useless otherwise.

--
Jeff Carter
"English bed-wetting types."
Monty Python & the Holy Grail
15


devel / comp.lang.ada / Variable value if exception is raised

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor