One of my pet peeves is poor error checking in LotusScript code. Even though we often use it for quick-and-dirty tasks within Domino/Notes, LotusScript is a real programming language and deserves to be treated as such.
The best way to illustrate the problem is with an example:
If you have spent a lot of time working with Domino/Notes, you have probably seen code like this. What's wrong with it? A lot. Let's suppose the view AllByName does not exist. Line 13 will fail and the view object NameView will be set to Nothing. Every other line in the program will fail as well, since the main view is missing. But, because there is no error checking, the LotusScript interpreter will try to continue processing, and will fail on line 14. (NameView is Nothing, so it does not have a method named GetDocumentByKey.) The user will receive the cryptic "object variable not set" error message, which does not really explain what the problem is.
What if view AllByName does exist? The code still has other problems. Line 14 assumes the view contains a document with the name "Tim Lewis." If there is no such document, line 14 will fail and set Doc to Nothing. Again, all lines that follow are invalid, and the user will see another mysterious "object variable not set" message. A similar problem is found at line 15, which assumes that a fie
To continue reading for free, register below or login
To read more you must become a member of SearchDomino.com
');
// -->

ld named Summary is present in the document. If it is not, the variable Summary will be set to the empty string. This is technically correct, but the comment tells us that we need a non-empty value for this string.
Here is the same code sample, with better error handling included:
Line 12 creates an error handling routine, which is found at line 32. The error handler is used in lines 18, 21 and 25. The three error conditions described above are checked for explicitly, with a meaningful error message displayed to the user in each case. Also, for each error, processing is halted so additional errors don't pile on top of each other.
In a follow-up tip next month, I will discuss the built-in LotusScript error handling mechanism (lines 12 and 32) in more detail and show how you can control it for your benefit.
More information can be found at Domino Designer Help / Contents / LotusScript / Error Processing.
About the author: Chuck Connell is president of CHC-3 Consulting, which helps organizations with all aspects of Domino and Notes.
Do you have comments on this tip? Let us know.
Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.