Runtime errors happen when we are actually executing the code. Most of these errors present error messages that users cannot easily understand. This recipe will show how to handle these errors as well as some of the most common errors.
Let's create a new codeunit from Object Designer.
Then add the following global variables:
Name
DataType
SubType
Customer
Record
Customer
Selection
Integer
Write the following code in the
OnRun
trigger of the codeunit: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?');
On execution of the codeunit, we will see a window with two options, as shown in the following screenshot: