#014 COLLECTABLE ERRORS IN AL
Since the release of Business Central 2021 wave 2, there is a feature that introduces a new way to raise errors, the Collectable Errors.
With this new feature, the system does not break the current activity, even if multiple errors are raised, until the code procedure ends. This improves the user experience as it will show the errors in one shot, instead of breaking the system for each error found.
How it works?
If during the execution of the code there were multiple errors, the first one will appear in the main section of the error window and the others will appear in the Detailed Information. To create a collectable error, we need the:
- [ErrorBehavior(ErrorBehavior::Collect)] syntax
- ErrorInfo must be set as Collectible(true)
Example:
The following function checks if some fields are empty in Customer Card.
Using the Collectible(true) method, the errors appear in the same window as shown below:
If we comment out the line where we set Collectible = true, the code will stop at the first error, displaying the message in Detailed Information.
Official documentation from Microsoft is available here:
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/errorinfo/errorinfo-data-type.