473,395 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 6554
"kimiraikkonen" <ki*************@gmail.comschrieb:
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
"kimiraikkonen" <ki*************@gmail.comwrote in message
news:3a**********************************@i3g2000h sf.googlegroups.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.atwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comschrieb:
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
"kimiraikkonen" <ki*************@gmail.comschrieb:
>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
"kimiraikkonen" <ki*************@gmail.comwrote in message
news:3a**********************************@i3g2000h sf.googlegroups.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.comwrote in message
news:uX**************@TK2MSFTNGP05.phx.gbl...
"kimiraikkonen" <ki*************@gmail.comwrote in message
news:3a**********************************@i3g2000h sf.googlegroups.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*****@interference.nitwrote in message
news:Ox**************@TK2MSFTNGP05.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.comwrote in message
news:ek**************@TK2MSFTNGP03.phx.gbl...
"Guru" <ru*****@interference.nitwrote in message
news:Ox**************@TK2MSFTNGP05.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*****@interference.nitwrote in message
news:uv****************@TK2MSFTNGP05.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.
bwahahahahahahahaha

Michael
Jan 21 '08 #10
"Michael C" <mi**@nospam.comwrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
"Guru" <ru*****@interference.nitwrote in message
news:uv****************@TK2MSFTNGP05.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.
That is precisely what I was implicating your code of being. I'll write you
up for one "I Know You Are But What Am I" lame.
>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.
There is absolutely nothing wrong with eating food you found in a dumpster,
if you're a rat.

If it is the case that "there was absolutely nothing wrong with the code"
then it necessarily follows that your earlier claim of "an empty string or
null would cause an exception" is false.
>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.

bwahahahahahahahaha
You're not very good at either programming or simple logic. Do you have any
redeeming attributes at all?
Jan 21 '08 #11
"Guru" <ru*****@interference.nitwrote in message
news:O$******************@TK2MSFTNGP03.phx.gbl...
You're not very good at either programming or simple logic. Do you have
any redeeming attributes at all?
You're really not very good at being a troll, although you do try very hard.
Sorry, but I am not playing your games.

Michael
Jan 21 '08 #12
Guru,

I hope that some day the calculation of your payment will fall in that by
you not catched try block.

This is what a real proffesional programmer never would do.

Just my thought about this kind of lazy programmer stuff you show.

Cor

Jan 21 '08 #13
You could easily check the MSIL code to see how on error resume next is
implemented.

Else I would do things the other way round. What are you trying to do ? Or
is it just curiosity about something you won't use ?
--
Patrice

"kimiraikkonen" <ki*************@gmail.coma écrit dans le message de news:
3a**********************************...oglegroups.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

Jan 21 '08 #14
"SurturZ" <su*****@newsgroup.nospamwrote in message
news:67**********************************@microsof t.com...
While guru is a bit obnoxious in his message style, I agree with his
sentiment.

There are plenty of cases where you would correctly use ON ERROR RESUME
NEXT
or a Try...Catch with an empty catch block.
That appeared to be the only point he was correct on though. His idea that
exceptions are slow due to sloppy programming is just plain wrong. His idea
that there are no reasons to avoid a Try Catch is just plain wrong. His
general perception of himself as some sort of guru is just plain wrong.
(Guru, if you reply to this I am not going to read your response let alone
reply to you).

Michael
Jan 23 '08 #15
"Michael C" <mi**@nospam.comwrote in message
news:uk**************@TK2MSFTNGP05.phx.gbl...
"SurturZ" <su*****@newsgroup.nospamwrote in message
news:67**********************************@microsof t.com...
>While guru is a bit obnoxious in his message style, I agree with his
sentiment.

There are plenty of cases where you would correctly use ON ERROR RESUME
NEXT
or a Try...Catch with an empty catch block.

That appeared to be the only point he was correct on though. His idea that
exceptions are slow due to sloppy programming is just plain wrong.
Correction, you lying dribble stain. You mentioned encountering a very slow
exception and I said, and I quote:

The long delay is indicative of a serious stack issue... more precisely,
stack corruption; there should be no delay.
Freaking liar.
His idea that there are no reasons to avoid a Try Catch is just plain
wrong.
Lying little sh1t. I said, and I quote:

I suggest that the strength of every single argument for avoiding them is
inversely proportional to how crappy a programmer you are.
His general perception of himself as some sort of guru is just plain
wrong.
Huh? My name _IS_ Guru, you brain-dead cowpat. Guru Sandaramurthy. I made no
claim to being a 'guru', and you know it, you lying pillock.
(Guru, if you reply to this I am not going to read your response let alone
reply to you).
Yeah... you don't want to see if your bare-faced lies get found out, I know.
Michael, The Lying Tapeworm.
Edited.
Jan 23 '08 #16
I for one am ignoring Guru's posts now, he's obviously a troll with no real
programming ability. In another thread he revealed that he thinks
Backhaus-Naur Form is a file protocol :lol:
--
David Streeter
Synchrotech Software
Sydney Australia
"Michael C" wrote:
"SurturZ" <su*****@newsgroup.nospamwrote in message
news:67**********************************@microsof t.com...
While guru is a bit obnoxious in his message style, I agree with his
sentiment.

There are plenty of cases where you would correctly use ON ERROR RESUME
NEXT
or a Try...Catch with an empty catch block.

That appeared to be the only point he was correct on though. His idea that
exceptions are slow due to sloppy programming is just plain wrong. His idea
that there are no reasons to avoid a Try Catch is just plain wrong. His
general perception of himself as some sort of guru is just plain wrong.
(Guru, if you reply to this I am not going to read your response let alone
reply to you).

Michael
Jan 23 '08 #17
"SurturZ" <su*****@newsgroup.nospamwrote in message
news:3E**********************************@microsof t.com...
>I for one am ignoring Guru's posts now, he's obviously a troll with no real
programming ability. In another thread he revealed that he thinks
Backhaus-Naur Form is a file protocol :lol:
I did no such thing, you lying spunkstain.
Jan 23 '08 #18
TYPO: Backus-Naur, not Backhaus-Naur

BNF. Whatever that stands for :-)

--
David Streeter
Synchrotech Software
Sydney Australia
"SurturZ" wrote:
I for one am ignoring Guru's posts now, he's obviously a troll with no real
programming ability. In another thread he revealed that he thinks
Backhaus-Naur Form is a file protocol :lol:
--
David Streeter
Synchrotech Software
Sydney Australia
"Michael C" wrote:
"SurturZ" <su*****@newsgroup.nospamwrote in message
news:67**********************************@microsof t.com...
While guru is a bit obnoxious in his message style, I agree with his
sentiment.
>
There are plenty of cases where you would correctly use ON ERROR RESUME
NEXT
or a Try...Catch with an empty catch block.
That appeared to be the only point he was correct on though. His idea that
exceptions are slow due to sloppy programming is just plain wrong. His idea
that there are no reasons to avoid a Try Catch is just plain wrong. His
general perception of himself as some sort of guru is just plain wrong.
(Guru, if you reply to this I am not going to read your response let alone
reply to you).

Michael

Jan 23 '08 #19
"SurturZ" <su*****@newsgroup.nospamwrote in message
news:3E**********************************@microsof t.com...
>I for one am ignoring Guru's posts now, he's obviously a troll with no real
programming ability.
Not only does he have no programming ability he's not even a very good
troll. A good troll will keep people hooked in, everyone's bailing on this
clown after a few posts.

Michael
Jan 23 '08 #20

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

Similar topics

7
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")...
3
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...
2
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...
5
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...
3
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...
7
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...
4
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...
11
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
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...
18
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.