Try..Catch vs On Error ???

  • Thread starter Thread starter Ralph
  • Start date Start date
R

Ralph

Hello everyone.

How is the function below accomplished in vb.net?

*************************
private function test

on error goto here

for i =0 to x
do something
do some more
do last bit
next

exit function

here:
if the error is this then
resume next 'jump back into the for/next loop
endif

end function
*************************
 
Ralph said:
Hello everyone.

How is the function below accomplished in vb.net?

*************************
private function test

on error goto here

for i =0 to x
do something
do some more
do last bit
next

exit function

here:
if the error is this then
resume next 'jump back into the for/next loop
endif

end function
*************************

*************************
private function test

for i =0 to x
do some things that can't go wrong
Try
do something that can go wrong
do some more
do last bit
Catch ex As Exception
' you may also use a more particular Exception object
' e.g. OleDbException
handle the error
Finally
clean up
End Try
next

end function
*************************
 
Thanks for the answer Jos.
Simple and sweet code.
I have to make an appointment at the hair restoration clinic after this one.
 
* "Ralph said:
How is the function below accomplished in vb.net?

*************************
private function test

on error goto here

for i =0 to x
do something
do some more
do last bit
next

exit function

here:
if the error is this then
resume next 'jump back into the for/next loop
endif

You will have to put every statement into a separate 'Try...Catch'
block.
 
One will work fine. I'm trying to ignore the "duplicate records being added
to a table error" and catch everything else.

Thanks for the input
 
Back
Top