:: Re: [DNG] C exception handling
Pàgina inicial
Delete this message
Reply to this message
Autor: Didier Kryn
Data:  
A: dng
Assumpte: Re: [DNG] C exception handling
Le 29/10/2024 à 14:43, Kevin Chadwick via Dng a écrit :
> 29 Oct 2024 13:20:40 Didier Kryn <kryn@???>:
>
>> This goes against program readability; and this is my major concern.
> However, does it go against program readability as the unhappy path is as important as the happy path.


    Yes the exceptional path is important and it is easily treated
apart, and it should be. The problem is only that the propagation (not
the treatment) of the exceptions corrupts the normal path all allong up
the call chain until the place where they will be treated. It reserves a
space in the range of the return values of all functions and forces the
callers to assert it. Just this bare propagation is one half of the
source code! It would be fine if it was separate, but it's interleaved
by design.

    I'm thinking more and more that, with my current development in C,
I need to experiment setjmp/longjmp for the first time. Otherwise it's
so ugly! I'm dealing with exceptional conditions detected by the program
itself, not zero-divide or the like happening by surprise -- these have
total legitimity to crash my program. I actually deal with just two
exceptions: Protocol_Error and Premature_End_Of_Data. These exceptions
can be detected by several functions, at various levels but must be
treated in just one place, near the top level of the application.

--     Didier