Notes Ninjas Notes Ninjas
Lotus Notes hints, tips, error messages
Golden Rule No7 Don't use On Error Resume Next

Hint Short Cut: Add this to your code & documentation to help you find this page.
http://www.notesninjas.com/#GR7 or http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/GR7


I hate On Error resume next. What does it do? It is basically a lazy programmer's way of handling errors in code. It tells the error handler to move on to the next line when there is an error. This can make sloppy code look like it sort of works but it can have catastrophic effects and is also a complete pain to debug.





When I have to fix other people's code, the first thing I do is comment out the On error resume next line, or replace it with some nice error handling code:

example:

On Error Goto ErrHdlr

'main code of routine

End

ErrHdlr:

' Put in some general error handling routines if necessary

If err=PossibelErrNo ' directory does not exist

 ' do something

else ' no specific error founc so do default action

 r=messagebox "Err:" & Err & " " & Error$ & " l: " & erl & " in " & CurFun & " - Try & continue?", 36, "Error"

 if r= 6 then ' user pressed yes

     resume next

 else ' user wants to stop

     print "Error " & Err & "  " & Error$ & " at line " & erl & " in function " & CurrentFunction

     end

 end if ' what did user press

end if ' error check

 

In Web agents you can change use the error handlers to actually stick out useful information which could help debug the code.

Stick the technical information as comments if you do not want to confuse the user.

eg:

print "An error has occurred.<br>"

print "<!-- Error line: " & erl & " -->"

 

NB If you see any on error resumes in my code, let me know I will remove them ASAP.

 

 Jump to:     Notes Tips
    Lotus Notes Index 
  Register for Tips
Previous Lotus Notes Tip 
    Next Lotus Notes Tip
Your company logo here?
Adam Foster
Free Cash Making Web Site
Free Revenue Earning Blog Site
 Free Revenue Earning Newsletter Site   
Free Search Pages Free Web stats
Free Contact Us page
Cheap .com domain names
 Need a website or 
   Lotus Notes
  problem solved?
Adam Foster
Web Services Platform Architecture: Soap, WSDL, WS-Policy, WS-Addressing, WS-Bpel, WS-Reliable Messaging and More by Francisco Curbera, Frank Leymann, Tony Storey, Donald Ferguson, Sanjiva Weerawarana
Other books claim to present the complete Web services platform architecture, but this is the first one I've seen that really does. The authors have been intimately involved in the creation of the architecture. Who better to write this book?
See at: Amazon.co.uk | Amazon.com |