:: Re: [DNG] another programming langu…
Top Page
Delete this message
Reply to this message
Author: Didier Kryn
Date:  
To: dng
New-Topics: [DNG] Error handling alternatives (was Re: another programming language question)
Subject: Re: [DNG] another programming language question
Le 25/10/2024 à 14:14, Kevin Chadwick via Dng a écrit :
> On 25/10/2024 12:39, Didier Kryn wrote:
>>     The last section, which is optionnal, is where you decide what to do with
>> exceptions, either cure the problem, print some smart information, convert it to
>> another exception and forward it to the caller, or what else.
>>
>>     After the "begin" and before the "exception" or the "end", is where the
>> normal algorithm happens. In this part, you don't care about exceptions, except
>> you can raise some, of course.
>>
> You can return from the local exception handler including a generic option type
> ala rust too or just an enum which is much nicer than a C code.
> The Ada community is traditionally, perhaps mostly with you Dider in regard to
> exceptions but some of us are not. I don't propagate exceptions with Ada because
> you can't on a light runtime but actually you can't miss handling something when
> it is right there and especially if you can't get to the procedures output
> unless it was successful (when using Ada to create an option type ala rust).
>
> The counter argument is that you should engineer software and exception handler
> locations properly but you can still do that with the more verbose error/success
> returning too.



    As usual, in Ada, you have several options to achieve your goal and
it is up to you to choose the most elegant. You can also use the
try-block method suggested by Karl, by inserting a short nested subprogram:

begin
/some code which might raise the exception/
exception
/the exception-handling code/
end

--     Didier