:: Re: [DNG] C exception handling
Kezdőlap
Delete this message
Reply to this message
Szerző: Didier Kryn
Dátum:  
Címzett: dng
Tárgy: Re: [DNG] C exception handling
Le 28/10/2024 à 21:04, Didier Kryn a écrit :
> Le 27/10/2024 à 20:58, karl@??? a écrit :
>> exceptions:
>> I saw in some ADA context it was inspired by the programmers
>> lazyness at checking return value. It seems to be a good way to
>> catch divide by zero, bound checking etc. longjmp is a very poor
>> replacement for that, but if it important enought you can always
>> do the checking yourself:
>> if (b == 0) { val = INT32_MAX; } // or whatever
>> else { val = a/b; }



    This discussion has been very usefull, at least to me because it
helped me to narrow down my concern about exception handling. Here it is.

    First: exception does not mean only exceptions detected by the OS
or the hardware, but includes those cases detected by the program itself.

    Second: the concern is not the detection of the exceptions but
their propagation. In C, appart from using setjmp/longjmp, the only way
for a callee to propagate an exception is to let the caller re-detect it
from either the return value or a modified variable. This re-detection,
repeated at every level of caller, is intermixed by design with the
logic of normal operation. This goes against program readability; and
this is my major concern.

--     Didier