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 MenuItemPrevNod e_Click(ByVal .snip..
Try
...A statement here
Catch
End Try
End Sub 8 1045
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" <ac******@a-znet.com> a écrit dans le message de
news:Ou******** ******@TK2MSFTN GP10.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 MenuItemPrevNod e_Click(ByVal .snip..
Try
..A statement here
Catch
End Try
End Sub
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" <ac******@a-znet.com> escribió en el mensaje
news:Ou******** ******@TK2MSFTN GP10.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 MenuItemPrevNod e_Click(ByVal .snip..
Try
..A statement here
Catch
End Try
End Sub
thanks
"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAM sogecable.com> wrote in message
news:uZ******** ******@tk2msftn gp13.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" <ac******@a-znet.com> escribió en el mensaje news:Ou******** ******@TK2MSFTN GP10.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 MenuItemPrevNod e_Click(ByVal .snip..
Try
..A statement here
Catch
End Try
End Sub
Actually I could do
if TreeViewFolders .SelectedNode.N extNode isnot nothing then
would that be better in some way?
thanks
"Patrice" <a@bc.c> wrote in message
news:Oh******** ******@TK2MSFTN GP09.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" <ac******@a-znet.com> a écrit dans le message de news:Ou******** ******@TK2MSFTN GP10.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 MenuItemPrevNod e_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
--
" academic" <ac************ @a-znet.comr> a écrit dans le message de
news:6d******** *************** ****@I2EYENET.C OM... Actually I could do
if TreeViewFolders .SelectedNode.N extNode isnot nothing then
would that be better in some way?
thanks
"Patrice" <a@bc.c> wrote in message news:Oh******** ******@TK2MSFTN GP09.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" <ac******@a-znet.com> a écrit dans le message de news:Ou******** ******@TK2MSFTN GP10.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 MenuItemPrevNod e_Click(ByVal .snip..
Try
..A statement here
Catch
End Try
End Sub
sounds good
thanks
"Patrice" <a@bc.c> wrote in message
news:%2******** ********@tk2msf tngp13.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" <ac************ @a-znet.comr> a écrit dans le message de news:6d******** *************** ****@I2EYENET.C OM... Actually I could do
if TreeViewFolders .SelectedNode.N extNode isnot nothing then
would that be better in some way?
thanks
"Patrice" <a@bc.c> wrote in message news:Oh******** ******@TK2MSFTN GP09.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" <ac******@a-znet.com> a écrit dans le message de > news:Ou******** ******@TK2MSFTN GP10.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 MenuItemPrevNod e_Click(ByVal .snip.. >> >> Try >> >> ..A statement here >> >> Catch >> >> End Try >> >> End Sub >> >> > >
> Actually I could do if TreeViewFolders .SelectedNode.N extNode 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
ok
thanks
"Jim Wooley" <ji************ *@hotmail.com> wrote in message
news:24******** *************** **@msnews.micro soft.com... Actually I could do
if TreeViewFolders .SelectedNode.N extNode 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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MLH |
last post by:
Consider the following 3 lines. If there are no records in tblStartUps
and the DMax in line 65 returns Null, a runtime error condition exists
in that Null is not a valid value for LastInRefNum. My question is
Is the Resume Next setting supposed to resume processing at A = 4 or
is it supposed to jump to line #70?
61 On Error Resume Next
|
by: Darta |
last post by:
OK- I volunteer to be shot if this question is stupid... BUT, is there
a way to, when you catch an exception in the catch{} handler, resume
to the same line of code that generated an error while you are
debugging within IDE...? Here is an example from VB:
Private SomeFunction ()
On Error GoTo ErrHandler:
MyMethod this, that
|
by: itsupport1 |
last post by:
Hi,
I am importing some records from one table to another table, and due to
Constraints in the destination table, it Throws an Exception and Skip the
Whole Rest of records.
So I did implement the On Error Resume next Statement, to avoid skipping the
process of Inserting the records.
But the Problem is
|
by: bob.needler |
last post by:
I know On Error Resume Next is generally considered lazy. But can
someone tell me why the resume next in Exit_Handler does not seem to
work? It generates the typical unhandled runtime error message from
Access. If I comment out the 1st On Error Resume Next and the x = 1 /
0 on the next line there is no difference, i.e. ther same unhandled
error on the same line. I included these 2 lines of code to
demonstrate that On Error Resume Next...
|
by: Neo |
last post by:
Hello All,
Although, I have read all the advantages of using Try Catch Block
instead of "On error goto", I am still confused what is alternative for
classic "Resume" statement. "Resume" was one of the crucial line in
debugging which let VB programmers go to exact line where error was
thrown.
I still use on error goto instead of try catch since, I want "Resume"
for debugging. Is there any alternative like Resume in VB.net for Try
| |
by: fniles |
last post by:
In VB 6.0 in the error trapping, we can do "resume next" to continue on the
next code. How can we do that in .NET with "Try", "Catch","End Try" ?
Thanks
|
by: Neo |
last post by:
I found on error resume next doesn't work in for each... e.g.
on error resume next
for each x in y
'do stuff
next
if you have an error in for each loop, it falls in infinite loop... it
doesn't move to next element... this sad thing but, it's indication
that we must move to try catch instead of on error.
|
by: Rob R. Ainscough |
last post by:
In VB6 I can use Resume Next to execute the line of coding following the
line that cause an exception. There doesn't appear to be anything similiar
when using Try...Catch -- so how can one resume the next statement when an
error can be ignored?
Thanks, Rob.
|
by: Maxwell2006 |
last post by:
Hi,
I know that this is not a good practice, but I wonder do we have "on error
resume next" in C#?
Thanks,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |