ERROR function

When an ERROR function is invoked, the execution of the current process terminates, the message is immediately displayed, and the database returns to the status it had following the last (implicit or explicit) COMMIT function as though the process calling the ERROR function had not run at all.

We can use the ERROR function in combination with the MESSAGE function to assist in repetitive testing. MESSAGE functions can be placed in code to show what is happening with an ERROR function placed just prior to where the process would normally complete. Because the ERROR function rolls back all database changes, this technique allows us to run through multiple tests against the same data without any time-consuming backup and restoration of our test data. The enhanced testing functionality built into NAV 2017 can accomplish the same things in a much more sophisticated fashion, but sometimes there's room for a temporary, simple approach.

An ERROR function call is formatted almost exactly like a MESSAGE call. ERROR has the syntax ERROR (String [, Value1] ,...]), where there are as many ValueX entries as there are %X substitution strings (up to 10). If the preceding MESSAGE was an ERROR function instead, the code line would be follows:

ERROR('Loop %1, Item No. %2',LoopCounter,"Item No.");

The display would look like the following screenshot:

The big X in a bold red circle tells us that this was an ERROR message, but some users might not immediately realize that. We can increase the ease of ERROR message recognition by including the word ERROR in our message, as shown in the following screenshot:

Even in the best of circumstances, it is difficult for a system to communicate clearly with the users. Sometimes our tools, in their effort to be flexible, make it too easy for developers to take the easy way out and communicate poorly or not at all. For example, an ERROR statement of the form ERROR('') will terminate the run, and roll back all data processing without even displaying any message at all. An important part of our job, as developers, is to ensure that our systems communicate clearly and completely.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.136.90