Try-Catch Code Blocks Unveiled!
After implementing the throw() command and introducing the Try(Expression) keyword, we are excited to unveil the next evolution in 4D’s error handling system: the introduction of Try-Catch code blocks!
A New Way to Handle Errors
We’ve recently introduced a new error-handling mechanism using the new throw() command.
This marked the first step towards a new error handling system, positioned as close as possible to the code generating them.
In the next phase with 4D v20 R4, we’re expanding this approach to intercept errors during expression execution.
Let’s delve into the details.
Enhanced Error Management in 4D Code
Throwing errors in your 4D code is now possible starting from v20R2.
Those errors behave as any 4D error: they trigger an error dialog or can be handled in an ON ERR CALL method.
This feature will ease your life because you’ll be able to improve the quality of your code by proactively detecting errors as soon as they occur. You can also handle better error logging.
Before digging into details, It’s important to note that this feature is the first step towards achieving robust error management.
Now, let’s dig into the details!
Catch errors everywhere
Error management is often a constraining part of development in all languages. In 4D, if you forget to call an error-handling method in a new process/worker or use components that don’t handle errors, the built-in 4D error dialog can appear to the final user. 4D developers would like to catch all errors in all contexts to avoid displaying this built-in 4D error dialog.
Let’s see how we can manage this behavior with 4D v19 R8.