Wednesday, July 25, 2012

Getting stack trace of error in LotusScript

Java has a wonderful method called printStackTrace which prints out the entire stack trace in case of exception. Unfortunately LotusScript does not have any similar functionality. But we can use On Error statement to reproduce this functionality.


So you have three sub routines Sub1, Sub2 and Sub3, with Sub1 calling Sub2 and Sub2 calling Sub3. In Sub3 there is an statement which will throw error. All the three sub routines have error handlers and none of them have Exit Sub statement so that the error drops from Sub3 to Sub2 to Sub1. All the errors are stored in global string variable errorStack.

Lets say you call Sub1 from click of button which has this code:


So now when you click on the button you will get a complete trace of the error with this message:


Make sure you add Exit Sub statement after displaying the error stack other wise you will get No RESUME error after showing the stack trace. This is a very simple example, but in case Sub3 is being called from multiple other sub routines then it can help in tracing exact path of error.

No comments:

Post a Comment