From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.5 required=3.0 tests=BAYES_05 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: John McCabe <"john@nospam.mccabe.org.uk"> Newsgroups: comp.lang.ada Subject: Re: Ada and "early return" - opinion/practice question Date: Tue, 16 Mar 2021 08:24:49 -0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <38356aa9-b8b0-4e0b-a490-99e7b239d0b1n@googlegroups.com> <86eegge32o.fsf@stephe-leake.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 16 Mar 2021 08:24:49 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="e18ab550129ff764d5cf1e3494dd6cd3"; logging-data="16935"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/esJRR0P5AxH5HzXtSb4mrctkzp5OayGY=" User-Agent: PhoNews/3.4.0 (Android/8.1.0) Cancel-Lock: sha1:LV7DFPRqqmV0fBa7CI5rDGuZKl0= In-Reply-To: <86eegge32o.fsf@stephe-leake.org> Xref: reader02.eternal-september.org comp.lang.ada:61546 List-Id: On 15/03/2021 17:31, Stephen Leake wrote: >John McCabe writes: > <..snip..> >> For example, you have a C++ function (pseudo code sort of thing): >> >> fn() >> { >> if () >> { >> return ; >> } >> >> if () >> { >> return ; >> } >> >> if () >> { >> return ; >> } >> >> // Only get here if everything's good... >> >> return ; >> } >> >I would tend to use an exception for "something bad", but that depends >on the overall design. Thinking back on this point, would you do it a style where you try to do what needs to be done then handle the exception when it fails? For example, in this style begin exception when blah blah end Or do you mean, rather than return when the undesirable condition occurs, do something like: if then raise end if; In other words, does each undesirable condition, when it occurs, throw a [potentially] different exception? Thanks John