|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Is it better to use Try or to use Resume Next?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 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 ? -- Show quoteHide quotePatrice " 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 > > 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 >> >> > > 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 > >> > >> > > > > > > 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 >> >> >> >> >> > >> > >> >> > > > Actually I could do Checking for expected invalid values is always prefered over just trying > > if TreeViewFolders.SelectedNode.NextNode isnot nothing then > > would that be better in some way? 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 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 > > 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. -- Show quoteHide quoteBest 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 > > 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 >> >> > >
Text Files: Number of Lines
Memory Leaking in VB.NET switch form sqlserver to access at runtime Address parameter in WebClient.UploadFile? Items property How to change color line by line in a rich textbox? Q: Dataview and a grid Unable to open file remotely vb.net2005 got error when put object VB 2005 |
|||||||||||||||||||||||