Home All Groups Group Topic Archive Search About

Is it better to use Try or to use Resume Next?

Author
21 Feb 2006 3:03 PM
academic
Sometime I have a situation where if an exception occurs I just want to
ignore and continue.

Is it better to use Try or to use Resume Next?



Or something else?

Thanks

Private Sub MenuItemPrevNode_Click(ByVal  .snip..

Try

...A statement here

Catch

End Try

End Sub

Author
21 Feb 2006 3:33 PM
Patrice
I would use Try for consistency but I would check first that I'm really
forced to do that. In particular can't you just do a test and quit the sub ?
Do you really have some unpredictable error you would like to ignore ?

--
Patrice

Show quoteHide quote
" academic" <acade***@a-znet.com> a écrit dans le message de
news:OuuSufvNGHA.1760@TK2MSFTNGP10.phx.gbl...
> Sometime I have a situation where if an exception occurs I just want to
> ignore and continue.
>
> Is it better to use Try or to use Resume Next?
>
>
>
> Or something else?
>
> Thanks
>
> Private Sub MenuItemPrevNode_Click(ByVal  .snip..
>
> Try
>
> ..A statement here
>
> Catch
>
> End Try
>
> End Sub
>
>
Author
21 Feb 2006 7:26 PM
academic
Actually I could do

if TreeViewFolders.SelectedNode.NextNode isnot nothing then


would that be better in some way?

thanks


Show quoteHide quote
"Patrice" <a@bc.c> wrote in message
news:Ohs7cwvNGHA.3276@TK2MSFTNGP09.phx.gbl...
>I would use Try for consistency but I would check first that I'm really
> forced to do that. In particular can't you just do a test and quit the sub
> ?
> Do you really have some unpredictable error you would like to ignore ?
>
> --
> Patrice
>
> " academic" <acade***@a-znet.com> a écrit dans le message de
> news:OuuSufvNGHA.1760@TK2MSFTNGP10.phx.gbl...
>> Sometime I have a situation where if an exception occurs I just want to
>> ignore and continue.
>>
>> Is it better to use Try or to use Resume Next?
>>
>>
>>
>> Or something else?
>>
>> Thanks
>>
>> Private Sub MenuItemPrevNode_Click(ByVal  .snip..
>>
>> Try
>>
>> ..A statement here
>>
>> Catch
>>
>> End Try
>>
>> End Sub
>>
>>
>
>
Author
22 Feb 2006 9:40 AM
Patrice
Yes IMO it's much cleaner :

1) when reading the code in few month, you won't necessarily remember why
you ignored errors (even harder for someone else). With an explicit test
you'll see at once that you don't perform this if you don't have a next
node...

2) if you have any other kind of error, it will be ignored too

IMHO you should never never run code that you know will cause an error.
Instead just don't call the code that would lead to this error...

Patrice
--

Show quoteHide quote
" academic" <academicNOSPAM@a-znet.comr> a écrit dans le message de
news:6dbef$43fb6957$455f1214$13498@I2EYENET.COM...
> Actually I could do
>
> if TreeViewFolders.SelectedNode.NextNode isnot nothing then
>
>
> would that be better in some way?
>
> thanks
>
>
> "Patrice" <a@bc.c> wrote in message
> news:Ohs7cwvNGHA.3276@TK2MSFTNGP09.phx.gbl...
> >I would use Try for consistency but I would check first that I'm really
> > forced to do that. In particular can't you just do a test and quit the
sub
> > ?
> > Do you really have some unpredictable error you would like to ignore ?
> >
> > --
> > Patrice
> >
> > " academic" <acade***@a-znet.com> a écrit dans le message de
> > news:OuuSufvNGHA.1760@TK2MSFTNGP10.phx.gbl...
> >> Sometime I have a situation where if an exception occurs I just want to
> >> ignore and continue.
> >>
> >> Is it better to use Try or to use Resume Next?
> >>
> >>
> >>
> >> Or something else?
> >>
> >> Thanks
> >>
> >> Private Sub MenuItemPrevNode_Click(ByVal  .snip..
> >>
> >> Try
> >>
> >> ..A statement here
> >>
> >> Catch
> >>
> >> End Try
> >>
> >> End Sub
> >>
> >>
> >
> >
>
>
Author
22 Feb 2006 5:48 PM
academic
sounds good
thanks


Show quoteHide quote
"Patrice" <a@bc.c> wrote in message
news:%23nYs6P5NGHA.3944@tk2msftngp13.phx.gbl...
> Yes IMO it's much cleaner :
>
> 1) when reading the code in few month, you won't necessarily remember why
> you ignored errors (even harder for someone else). With an explicit test
> you'll see at once that you don't perform this if you don't have a next
> node...
>
> 2) if you have any other kind of error, it will be ignored too
>
> IMHO you should never never run code that you know will cause an error.
> Instead just don't call the code that would lead to this error...
>
> Patrice
> --
>
> " academic" <academicNOSPAM@a-znet.comr> a écrit dans le message de
> news:6dbef$43fb6957$455f1214$13498@I2EYENET.COM...
>> Actually I could do
>>
>> if TreeViewFolders.SelectedNode.NextNode isnot nothing then
>>
>>
>> would that be better in some way?
>>
>> thanks
>>
>>
>> "Patrice" <a@bc.c> wrote in message
>> news:Ohs7cwvNGHA.3276@TK2MSFTNGP09.phx.gbl...
>> >I would use Try for consistency but I would check first that I'm really
>> > forced to do that. In particular can't you just do a test and quit the
> sub
>> > ?
>> > Do you really have some unpredictable error you would like to ignore ?
>> >
>> > --
>> > Patrice
>> >
>> > " academic" <acade***@a-znet.com> a écrit dans le message de
>> > news:OuuSufvNGHA.1760@TK2MSFTNGP10.phx.gbl...
>> >> Sometime I have a situation where if an exception occurs I just want
>> >> to
>> >> ignore and continue.
>> >>
>> >> Is it better to use Try or to use Resume Next?
>> >>
>> >>
>> >>
>> >> Or something else?
>> >>
>> >> Thanks
>> >>
>> >> Private Sub MenuItemPrevNode_Click(ByVal  .snip..
>> >>
>> >> Try
>> >>
>> >> ..A statement here
>> >>
>> >> Catch
>> >>
>> >> End Try
>> >>
>> >> End Sub
>> >>
>> >>
>> >
>> >
>>
>>
>
>
Author
22 Feb 2006 6:55 PM
Jim Wooley
> Actually I could do
>
> if TreeViewFolders.SelectedNode.NextNode isnot nothing then
>
> would that be better in some way?

Checking for expected invalid values is always prefered over just trying
to use something that doesn't exist and trap it in an exception handler.
The framework is full of type checking even for simple expression evaluators.
The performance hit for checking is insignificant to the hit for throwing
and handling an exception. My favorite analogy holds: Don't pee in your pants
to check to see if your fly is open.

Jim Wooley
Author
22 Feb 2006 9:49 PM
academic
ok

thanks

Show quoteHide quote
"Jim Wooley" <jimNOSPAMwooley@hotmail.com> wrote in message
news:24f81e8e081b8c805cec5f00bba@msnews.microsoft.com...
>> Actually I could do
>>
>> if TreeViewFolders.SelectedNode.NextNode isnot nothing then
>>
>> would that be better in some way?
>
> Checking for expected invalid values is always prefered over just trying
> to use something that doesn't exist and trap it in an exception handler.
> The framework is full of type checking even for simple expression
> evaluators. The performance hit for checking is insignificant to the hit
> for throwing and handling an exception. My favorite analogy holds: Don't
> pee in your pants to check to see if your fly is open.
>
> Jim Wooley
>
>
Author
21 Feb 2006 3:38 PM
Carlos J. Quintero [VB MVP]
Hi,

If you have only one statement whose exceptions you want to ignore, use the
Try/Catch block.

If there are several statements that you want to execute even if one of them
fails, use the On Error Resume Next statement. Doing the same with Try/Catch
would require one block for each statement, which for a large number of
statements is overkill.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com


Show quoteHide quote
" academic" <acade***@a-znet.com> escribió en el mensaje
news:OuuSufvNGHA.1760@TK2MSFTNGP10.phx.gbl...
> Sometime I have a situation where if an exception occurs I just want to
> ignore and continue.
>
> Is it better to use Try or to use Resume Next?
>
>
>
> Or something else?
>
> Thanks
>
> Private Sub MenuItemPrevNode_Click(ByVal  .snip..
>
> Try
>
> ..A statement here
>
> Catch
>
> End Try
>
> End Sub
>
>
Author
21 Feb 2006 7:24 PM
academic
thanks

Show quoteHide quote
"Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in message
news:uZGIczvNGHA.3728@tk2msftngp13.phx.gbl...
> Hi,
>
> If you have only one statement whose exceptions you want to ignore, use
> the Try/Catch block.
>
> If there are several statements that you want to execute even if one of
> them fails, use the On Error Resume Next statement. Doing the same with
> Try/Catch would require one block for each statement, which for a large
> number of statements is overkill.
>
> --
>
> Best regards,
>
> Carlos J. Quintero
>
> MZ-Tools: Productivity add-ins for Visual Studio
> You can code, design and document much faster:
> http://www.mztools.com
>
>
> " academic" <acade***@a-znet.com> escribió en el mensaje
> news:OuuSufvNGHA.1760@TK2MSFTNGP10.phx.gbl...
>> Sometime I have a situation where if an exception occurs I just want to
>> ignore and continue.
>>
>> Is it better to use Try or to use Resume Next?
>>
>>
>>
>> Or something else?
>>
>> Thanks
>>
>> Private Sub MenuItemPrevNode_Click(ByVal  .snip..
>>
>> Try
>>
>> ..A statement here
>>
>> Catch
>>
>> End Try
>>
>> End Sub
>>
>>
>
>