|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
On Error Goto Next LoopHi, 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 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... -- Patrice "Lucia" <cheng_lu***@yahoo.com> a écrit dans le message de news: 1161156478.770535.234***@m7g2000cwm.googlegroups.com...Show quoteHide quote > 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 > 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 But this is definitely the best solution...> 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... 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.. Show quoteHide quote "Lucia" wrote: > 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 > > 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] Show quoteHide quote "Lucia" wrote: > 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 > > 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 Show quoteHide quote "M. Posseth" wrote: > > 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" wrote: > > > 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 > > > >
Need a tip: How do you streamwrite from two different db tables?
Recognizing if SQL Server is installed (and what version) Q: Advice on threads open source .NET search engine? How to simulate Application.DoEvents in a DLL Dispose problem/crash with maximized MDI child windows Bootstrapping .NET 2.0 VB2005 - Split Files Visual Basic Programming - Reference to fpPublishLogInTempDir uri - ADVANCED question Uninstall a device |
|||||||||||||||||||||||