473,835 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

On Error Resume Next

Hi,
I want to find out if there's difference between "On Error Resume
Next" error handler and leaving "catch" block empty in a try-catch-end
try block to ignore exceptions which i don't approve of course but
just needed to ask.

Thanks
Jan 20 '08 #1
19 6598
"kimiraikko nen" <ki************ *@gmail.comschr ieb:
I want to find out if there's difference between "On Error Resume
Next" error handler and leaving "catch" block empty in a try-catch-end
try block to ignore exceptions which i don't approve of course but
just needed to ask.
'On Error Resume Next' will continue execution on the next statement after
the statement which raised the error/threw the exception whereas
'Try...Catch' will stop execution and jump directly into the 'Catch' block.

\\\
On Error Resume Next
<Statement 1>
<Statement 2 ' Statement throwing an exception.
<Statement 3>
On Error GoTo 0
///

In the code above <Statement 3will be executed, but it won't be executed
in the code sample below:

\\\
Try
<Statement 1>
<Statement 2 ' Statement throwing an exception.
<Statement 3>
Catch
End Try
///

To archieve similar behavior to 'On Error Resume Next' you'd have to put
each statement in a separate 'Try...Catch' block.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 20 '08 #2
"kimiraikko nen" <ki************ *@gmail.comwrot e in message
news:3a******** *************** ***********@i3g 2000hsf.googleg roups.com...
Hi,
I want to find out if there's difference between "On Error Resume
Next" error handler and leaving "catch" block empty in a try-catch-end
try block to ignore exceptions which i don't approve of course but
just needed to ask.

Thanks
On Error Resume Next
Statement 1
Statement 2
....

is the same as

Try
statement 1
catch
end try
try
statement 2
catch
end try
....

Mike.
Jan 20 '08 #3
On Jan 21, 12:05*am, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrot e:
"kimiraikko nen" <kimiraikkone.. .@gmail.comschr ieb:
I want to find out if there's difference between "On Error Resume
Next" error handler and leaving "catch" block empty in a try-catch-end
try block to ignore exceptions which i don't approve of course but
just needed to ask.

'On Error Resume Next' will continue execution on the next statement after
the statement which raised the error/threw the exception whereas
'Try...Catch' will stop execution and jump directly into the 'Catch' block..

\\\
On Error Resume Next
<Statement 1>
<Statement 2* *' Statement throwing an exception.
<Statement 3>
On Error GoTo 0
///

In the code above <Statement 3will be executed, but it won't be executed
in the code sample below:

\\\
Try
* * <Statement 1>
* * <Statement 2* *' Statement throwing an exception.
* * <Statement 3>
Catch
End Try
///

To archieve similar behavior to 'On Error Resume Next' you'd have to put
each statement in a separate 'Try...Catch' block.

--
*M S * Herfried K. Wagner
M V P *<URL:http://dotnet.mvps.org/>
*V B * <URL:http://dotnet.mvps.org/dotnet/faqs/>
Thanks for the nice explanation. Could a funny approach would be for
try-catch to do the same with "on error resume next"? :-)

Try
<statement1>
<statement2' Exception occurs for statement2
<statement3>

Catch
<statement3' If a exception is occured in <statement2>

End Try

A bit funny...
Jan 20 '08 #4
"kimiraikko nen" <ki************ *@gmail.comschr ieb:
>Thanks for the nice explanation. Could a funny approach would be for
try-catch to do the same with "on error resume next"? :-)

Try
<statement1>
<statement2' Exception occurs for statement2
<statement3>

Catch
<statement3' If a exception is occured in <statement2>

End Try

A bit funny...
Sorry, I am not sure if you are serious :-). The code above won't be
semantically equivalent to the 'On Error Resume Next' code because it won't
catch an exception if <Statement 3throws an exception and it won't execute
<Statement 2if <Statement 1throws an exception.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 20 '08 #5
"kimiraikko nen" <ki************ *@gmail.comwrot e in message
news:3a******** *************** ***********@i3g 2000hsf.googleg roups.com...
Hi,
I want to find out if there's difference between "On Error Resume
Next" error handler and leaving "catch" block empty in a try-catch-end
try block to ignore exceptions which i don't approve of course but
just needed to ask.
There is nothing wrong with ignoring errors if that is the behaviour you're
after. Ignoring errors on a large block of code is really bad however.
Generally it's not necessary to ignore errors for more than 1 line of code
so the try catch would be best. I think it's best to use On Error as this is
a VB6 hangover and there is no direct translation for C#.

Michael
Jan 21 '08 #6
"Michael C" <mi**@nospam.co mwrote in message
news:uX******** ******@TK2MSFTN GP05.phx.gbl...
"kimiraikko nen" <ki************ *@gmail.comwrot e in message
news:3a******** *************** ***********@i3g 2000hsf.googleg roups.com...
>Hi,
I want to find out if there's difference between "On Error Resume
Next" error handler and leaving "catch" block empty in a try-catch-end
try block to ignore exceptions which i don't approve of course but
just needed to ask.

There is nothing wrong with ignoring errors if that is the behaviour
you're after. Ignoring errors on a large block of code is really bad
however. Generally it's not necessary to ignore errors for more than 1
line of code so the try catch would be best. I think it's best to use On
Error as this is a VB6 hangover and there is no direct translation for C#.

Michael
You are correct that there are limited applications for On Error Resume
Next. The one application I have found (even in VB6) was during
initialization of an application. You set up default values and then call a
sub that uses On Error Resume Next so that if changes to the defaults based
on the current run time environment fail, you simply keep on going.

Mike Ober.
Jan 21 '08 #7
"Guru" <ru*****@interf erence.nitwrote in message
news:Ox******** ******@TK2MSFTN GP05.phx.gbl...
So, now that you have been given 200,001 valid reasons (200,000 equality
comparisons plus your job security) in favour of using empty Catch
clauses,
please provide one single, solitary but equally valid reason for not using
them.
Well, they are slow when they do happen. I had a similar situation where an
empty string or null would cause an exception. The delay was quite
noticeable in some cases (1 sec or more). By adding in the check it became
instant. I'm not suggesting what you're saying was wrong, but you appeared
to be suggesting there was no reasons to avoid them.

Michael
Jan 21 '08 #8
"Michael C" <mi**@nospam.co mwrote in message
news:ek******** ******@TK2MSFTN GP03.phx.gbl...
"Guru" <ru*****@interf erence.nitwrote in message
news:Ox******** ******@TK2MSFTN GP05.phx.gbl...
>So, now that you have been given 200,001 valid reasons (200,000 equality
comparisons plus your job security) in favour of using empty Catch
clauses,
please provide one single, solitary but equally valid reason for not
using
them.

Well, they are slow when they do happen. I had a similar situation where
an empty string or null would cause an exception. The delay was quite
noticeable in some cases (1 sec or more). By adding in the check it became
instant.
The long delay is indicative of a serious stack issue... more precisely,
stack corruption; there should be no delay. What you did was kludge your
code and leave the root cause completely unresolved. The cause is still
there in your code, lurking, waiting, ready to scribble all over your
customer's valuable data at the first opportune moment and in a completely
unexpected place elsewhere in the application.

To put that a different way, when faced with a delay in an exception, the
question you should ask yourself is, why is the code falling over at all,
not, how can you kludge your badly-written code without finding and fixing
the cause.
but you appeared to be suggesting there was no reasons to avoid them.
I suggest that the strength of every single argument for avoiding them is
inversely proportional to how crappy a programmer you are.

Touché to me.

HTH


Jan 21 '08 #9
"Guru" <ru*****@interf erence.nitwrote in message
news:uv******** ********@TK2MSF TNGP05.phx.gbl. ..
The long delay is indicative of a serious stack issue... more precisely,
stack corruption; there should be no delay. What you did was kludge your
code and leave the root cause completely unresolved. The cause is still
there in your code, lurking, waiting, ready to scribble all over your
customer's valuable data at the first opportune moment and in a completely
unexpected place elsewhere in the application.
What a complete and utter load of rubbish.
To put that a different way, when faced with a delay in an exception, the
question you should ask yourself is, why is the code falling over at all,
not, how can you kludge your badly-written code without finding and fixing
the cause.
You really have no idea what my code was like. There was absolutely nothing
wrong with the code or the structure of it.
I suggest that the strength of every single argument for avoiding them is
inversely proportional to how crappy a programmer you are.
You clearly are an idiot.
Touché to me.
bwahahahahahaha haha

Michael
Jan 21 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5207
by: jason | last post by:
Is there a way to avoid On Error Resume Next for: cnn.Open strCon SQL = "EXEC Customer @txtEmail='" & email_address & "'" set rs = cnn.execute(SQL) 'On error resume next rs("email_address") '// This record does not exist thus throwing up an error. I could use On
3
2222
by: Laphan | last post by:
Hi Everybody I put the On Error Resume Next command as the very first line in my ASP pages, which may contain various inc files and sub-routines/functions, so that I can try and stop the dreaded DB error messages displaying to visitors and would-be hackers. My question is, does this one statement at the top of the page cater for all of the code that might be executed in the page, in the include files and in sub-routines/functions or...
2
419
by: tom blower | last post by:
Access 2k (10.6501.6714) SP3 For YEARS the code line "On Error Resume Next" has worked without any problems. It is an essential tool. A couple of days ago, I put in another hard drive, mentioned because the problems have arisen since then, and transferred a lot of files, mainly MDB files, to the new drive. This line of code now fails to work in all the databases I have tried. I get error messages where none appeared before. I tried to...
5
8614
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
3
27441
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...
7
17201
by: bikesandcars | last post by:
Hello guys, I stumbled upon this forum recently and am hoping someone here can help me with this problem. This is probably very stupid, but I can't get past this easy problem / glitch. All I need to do is test if a table exists, and then delete it if it does (so I can create a new one). Of course, you can't delete a table if it doesn't exist, and this returns an error. Every source I've looked at says an easy way to solve this...
4
3788
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.
11
48015
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,
4
5112
esimond
by: esimond | last post by:
Hi All ! Just joined this big community, and a BIG Swiss Hello in there ! Having recently switched from VB to C#, I indeed still have to discover all the powerful sides of that great language. OK, try catch finally are great, but...
18
2620
by: julietbrown | last post by:
Can you boost my understanding of Access? I don't like things I can 'cure' but don't understand why! I've converted the Save macro on my form to VBA. It looks like this ... as I'm sure you already know. Private Sub SaveChanges_Click() On Error GoTo SaveChanges_Click_Err On Error Resume Next DoCmd.RunCommand acCmdSaveRecord
0
9803
marktang
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...
0
10808
Oralloy
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...
1
10560
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,...
0
10233
tracyyun
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...
1
7766
isladogs
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...
0
5636
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...
1
4433
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3088
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.