Friday, April 02, 2010

Error handling in Notes

If we were using .NET or Java, we could easily handle errors using Try and Catch, but that's not the case in Notes, so it's important to know where exactly the error occurred - which module, what line and where it was called from. Knowing this information helps us resolve the problem in a quick and efficient manner. Let's now look at how we can achieve something similar in Notes:

Msgbox Lsi_info(2) & " called by " & Lsi_info(12) & "(" & Lsi_info(430) & "): " & Error$ & " - Line: " & Cstr(Erl), 16, "Title"

I read an interesting article on Dominopower (http://www.dominopower.com/issues/issue200606/00001780001.html), which lead me to update my error handling code.

So what does it do you may ask:

1) Lsi_info(2) - returns the current module/sub/function name
2) Lsi_info(12) - returns the parent module that called this routine or function.
3) Lsi_info(430) - returns the line number in the calling module that called this module.


It's always a good idea to log all your errors in a database as well as displaying a generic error message to the user. This is where Julian Robichaux's OpenLog (http://www.openntf.org/Projects/pmt.nsf/ProjectLookup/OpenLog) template comes in handy.

No comments: