Urgent.News

What's breaking now, across hundreds of outlets.

Tech

TRY/CATCH en Genero BDL: qué captura y qué no (guía rápida)

Un TRY/CATCH alrededor de una llamada parece una red de seguridad completa: si algo falla dentro de la función, el CATCH se encargará. En Genero BDL no funciona así, y no saberlo lleva a programas que se paran sin pasar por el CATCH o a errores que pasan en silencio. El problema: un TRY que no salta Fíjate en este programa. Cada llamada va dentro de su propio TRY y cada función falla: una divide…

Original Spanish headline Read in English

TRY/CATCH is a safety net for functions in Genero BDL, but it doesn't work as expected. A TRY block does not cover function calls, which can lead to unexpected errors. In the provided example, a division by zero occurs within a function, but the program stops without triggering the CATCH block. The issue lies in the fact that a TRY statement covers lines, not function calls.

The Genero manual describes TRY/CATCH as a pseudoinstruction: the compiler generates no code for these lines, and the block behaves like a WHENEVER ANY ERROR GOTO, affecting only the lines within TRY and CATCH. Therefore, the divide() and abre_formulario() functions are not included within the TRY block. The default error handling applies to these functions: program errors like division by zero are ignored, while expression errors are handled by the CATCH block.

Errors within TRY or CATCH blocks are captured, including expression errors and database-related errors. The status code, error text, and SQL code are available within the CATCH block. To propagate errors from a function to its caller, the function must raise the error using WHENEVER ERROR RAISE. In the provided example, changing MAIN to:

MAIN

WHENEVER ANY ERROR RAISE

TRY CALL divide()

CATCH DISPLAY "divide: capturado ", status

END TRY

TRY CALL abre_formulario()

CATCH DISPLAY "abre_formulario: capturado ", status

END TRY

DISPLAY "fin"

END MAIN

ensures that errors from divide() and abre_formulario() are propagated to the MAIN function's TRY block. This way, errors are caught and displayed accordingly. The example demonstrates that TRY/CATCH covers lines within the same module, while WHENEVER ANY ERROR RAISE is needed to propagate errors from called functions.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

More from Dev.to on urgent.news

Report a problem with this story

Get the day's news by email. Daily, weekly or monthly. Sign up

More in Tech

More from Tuesday, 1 December 2026 →