Sunday, March 15, 2009

Forgotten Notes Features: GetThreadInfo()

When reviewing LotusScript code, every other time I find the following lines of code for errorhandling:

errHandler:
msgbox "An error occured in procedure 'myProcedure' in line " & erl & ": " & error
(replace "msgbox" by "doLog()" or whatever way of logging you prefer / do).

And in each other procedure, the name of the procedure is hardcoded in the errorhandler again. Well, while LotusScript might not have the best error tracing features, it does give you at least some dynamic system information that you can use. In this case, a centralized errorhandling function using GetThreadInfo() would help:

errHandler:
Call logThis(GetThreadInfo(LSI_THREAD_PROC))

Sub logThis(procedureName as String)
   msgbox "An error occured in procedure '" & procedureName & "' in line " & erl & ": " & error
End Sub

More beautiful options for the parameter are:
  • LSI_THREAD_CALLPROC for the name of the calling procedure
  • LSI_THREAD_MODULE for the name of the module
  • LSI_THREAD_LINE for the current line number
...and many more.
And you even don't have to add any %Include directives for the constants. It's easy, it's simple, it's convenient, it helps...

Do you have a good errorhandling routine you use? Place it in the comments and share it with the community.

2 Comments:

Blogger Jim Knight said...

Thanks for the reminder. This is a good one to use.

March 16, 2009 1:20 AM  
Blogger marcusfoerster said...

Hi Jim,
Thanks for your comment. Yes, I love that command, and it is so easy to use.

March 16, 2009 2:47 AM  

Post a Comment

Thank you for your comment. It will be published shortly. Keep having a great day!

<< Home