Handling runtime errors
Runtime errors happen when you are actually executing code. Most of these errors present error messages that users cannot easily understand. This recipe will show you how to handle these errors as well as some of the most common ones.
How to do it...
Create a new codeunit from Object Designer.
Add the following global variables:
Name
Type
Subtype
Customer
Record
Customer
Selection
Integer
Add the following code to the
OnRun
trigger:Selection := STRMENU('Show Error,Handle Error', 1); IF Selection = 1 THEN Customer.GET ELSE IF NOT Customer.GET THEN ERROR(' Unable to find a customer with a blank number. \Are you sure you have selected a customer?');
Save and close the codeunit.
How it works...
This codeunit allows you to select between having NAV handle an error for you or handling it with custom code. If you choose to let NAV handle the error for you, you will be presented with this error message:
This message can be confusing for new users. Its interpretation can...