On Error Goto Next Loop

L

Lucia

Hi, everyone,

I have a for statement in my programm. I want to know if there is any
way to goto next i when some error occurs. I tried with the following
code. But it doesn't work...

for i=0 to 100

On Error Goto NEXTFOR

.....

NEXTFOR:
next

thanks a lot

Lucia
 
P

Patrice

Works here. What is the error you try to catch ? My first thought would be
that this is actually not considered as an error...

Actually I'm not using this style anymore. My personal preference would be
to use try catch. Also if this is something that can be controlled before
hand I prefer to test that the statement won't raise an error before issuing
it, rather than letting the error happens and handle it afterward...
 
N

Norman Chong

Patrice schrieb:

Try-Catch-blocks are better than GOTOs, especially when you need a lot
of error-handling - When you have 150 different error-handlers within a
project, you might get a little confused... ;-)
Also if this is something that can be controlled before
hand I prefer to test that the statement won't raise an error before issuing
it, rather than letting the error happens and handle it afterward...

But this is definitely the best solution...
 
G

Guest

If you are using VB 2005, then there is a Continue statement, that will skip
to the next iteration of the For loop, without using Goto..
 
G

Guest

for i=0 to 100

try
'code that might cause an error
catch ex as exception
'this will skipp the curent and move to the next
continue for
end try

next

regards

Michel Posseth [MCP]
 
G

Guest

ofcourse it would be much better if you could do something like this

PSEUDO CODE :

for i=0 to 100


---- check if value is within the expected range
if not expectedrangecode then
continue for
end if
--- do the rest of youyr stuff
next

as this would give you a performance benefit ( try catch statements have a
lot of overhead ) so if you can validate the values yourself without try
catch then implement this validation

regards

Michel




M. Posseth said:
for i=0 to 100

try
'code that might cause an error
catch ex as exception
'this will skipp the curent and move to the next
continue for
end try

next

regards

Michel Posseth [MCP]



Lucia said:
Hi, everyone,

I have a for statement in my programm. I want to know if there is any
way to goto next i when some error occurs. I tried with the following
code. But it doesn't work...

for i=0 to 100

On Error Goto NEXTFOR

.....

NEXTFOR:
next

thanks a lot

Lucia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top