Friday, November 5, 2010

On Error Resume Next - usage and demerits

On Error Resume Next - usage and demerits


You can add this "On Error Resume Next" to hide any code execution errors to pop-up on your screen
if you know you would get an error in the code block.
You must use "On Error goto 0" to activate error-handling mechanism , after the code of block if finished executing, so that if there any consequent errors in the remaining block of code, you will come to know there are errors.

It so happened to me , that i used "On Error Resume Next" before

if Data1(i)<>Data2(i) then

so that, my code execution would not stop and happily my code got executed.
But i was unaware that on adding "On Error Resume Next" would really cause me problems.
If there was data or invalid data, you cant compare them, naturally it would throw u error
sayimg "Subscript out of range" or "cant compare with /null"
you should write an exception mechanism to control  the flow of execution to get uninterrupted.

Check if your code can handle the error , and if you continously get "Null" values,
and if you are using any resultset or dbconnections, use RS.MoveFirst after Rs.Next loop if any.

No comments:

Post a Comment