:: Re: [DNG] Error handling alternativ…
Page principale
Supprimer ce message
Répondre à ce message
Auteur: Didier Kryn
Date:  
À: dng
Sujet: Re: [DNG] Error handling alternatives (was Re: another programming language question)
Le 26/10/2024 à 11:38, karl@??? a écrit :
> Karl:
> ...
>
> this code:
> LOG_VIF( cnti != cnto, LOG_ERR, " cnti = %ld, cnto = %ld", cnti, cnto ) { return -1; }
> gives this:
>> 2024-10-16_21:33:53: ERR run.c 62: <cnti != cnto> cnti = 0, cnto = 3
> ...
>
> when the test failed. I.e. I can see a copy of the actual test:
> "cnti != cnto" in the log. I get that by including a copy of
> the test "f" text in the printout:
>
> #define LOG_VIF( f, lvl, format, ... ) \
> if ( (f) && ( LOG_PRINTF(lvl, "<%s>" format, #f, __VA_ARGS__), 1 ) )
>
> Can I get that in ADA too ?
>
> I think it is nice to see the actual test that triggered the log line
> in the log.
>

    Karl, it is difficult to follow you into your cpp macros. Also,
this shouldn't turn to a lecture on Ada because both it would be very
off topic, and I'm not ready for that.

    You are relying on preprocessor macros to do things C proper cannot
do. This is a dead-end and you know it. Preprocessor macros must be used
with moderation. They undergo no syntax analysis and the compiler
diagnostics is made on the expanded code instead of your actual source.
If you are counting on these tricks, it means you have hit the maximum
level of complexity which can reasonably be reached with this language.

    However there is another technique which can be used in C to let
exceptions follow a different flow path, and is implemented in the
runtime library. This is the setjmp/longjmp technique; I have no
experience with it but I understand that's roughly what it's intended
for. I think it's the only way to implement a smarter exception handling
in C, though, as usual in C, you need to carve it all by hand. I do
think it's the best C can give you in this matter.

--     Didier