473,387 Members | 1,420 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,387 software developers and data experts.

Do we have "on error resume next" in C#?

Hi,

I know that this is not a good practice, but I wonder do we have "on error
resume next" in C#?

Thanks,

Max
Nov 13 '06 #1
11 47896
Max,

No. Are you nuts? :)

Seriously, no, there isn't, and all for the reasons that you'd expect.
There's really a whole lot you can do with try/catch blocks. Carefully
constructed code could do the same and more. Ask if you have a specific
need that someone may be able to help with.
Stephan
Maxwell2006 wrote:
Hi,

I know that this is not a good practice, but I wonder do we have "on error
resume next" in C#?

Thanks,

Max
Nov 13 '06 #2
I know that this is not a good practice, but I wonder do we have "on error
resume next" in C#?
Try..catch..finally is the best way... "on error resume next" would be
something horrible :-)

--

//\/\\3rL1n_______
Nov 13 '06 #3
Maxwell2006 <al******@newsgroup.nospamwrote:
I know that this is not a good practice, but I wonder do we have "on error
resume next" in C#?
Fortunately not. Similar functionality can be obtained by using
try/catch within a loop.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 13 '06 #4
Maxwell2006 wrote:
I know that this is not a good practice, but I wonder do we have "on error
resume next" in C#?
Fortunately, no we do not. You could emulate it by putting a try/catch
around each line of code. By doing so you quickly see why "on error resume
next" is such a bad idea in VB.
--
Tom Porterfield

Nov 13 '06 #5
Merlin <Me****@LesFees.Netwrote:
I know that this is not a good practice, but I wonder do we have "on error
resume next" in C#?

Try..catch..finally is the best way... "on error resume next" would be
something horrible :-)
In fact, try/finally is usually better than try/catch/finally - there
should generally be many more finally statements than catch statements,
as that indicates you have centralised error handling. It's not always
the case, but it's a good rule of thumb.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 13 '06 #6

There was a "tension" when bringing vb6 to vb.net

this was one of the thing brought over, even though it was kind of a bad
thing.

That's why it was a vb.net thing only, because c# didn't have to deal with
the "upgrade" tension of vb6.

I'm just trying to share the ~why as opposed to the yes/no of it.

..net 2.0 tries to ease more of this "tension" by using the My. keyword to
wrap up some common functionality.


"Maxwell2006" <al******@newsgroup.nospamwrote in message
news:e%****************@TK2MSFTNGP02.phx.gbl...
Hi,

I know that this is not a good practice, but I wonder do we have "on error
resume next" in C#?

Thanks,

Max


Nov 13 '06 #7
Merlin <Me****@LesFees.Netwrote:
In fact, try/finally is usually better than try/catch/finally - there
should generally be many more finally statements than catch statements,
as that indicates you have centralised error handling. It's not always
the case, but it's a good rule of thumb.
I fully agree. But it's hard to give generic laws, all depends on the
code style and a few variants can be accepted. try/finally or try/catch
or try/catch/finally are there and are all powerfull ways to build
code, but, of course, syntax elements are nothing if there's not a
solid plan in the mind of the developer...

--

//\/\\3rL1n_______
Nov 15 '06 #8
Jon Skeet wrote:
>In fact, try/finally is usually better than try/catch/finally - there
should generally be many more finally statements than catch statements,
as that indicates you have centralised error handling. It's not always
the case, but it's a good rule of thumb.
Merlin wrote:
>I fully agree. But it's hard to give generic laws, all depends on the
code style and a few variants can be accepted. try/finally or try/catch
or try/catch/finally are there and are all powerfull ways to build
code, but, of course, syntax elements are nothing if there's not a
solid plan in the mind of the developer...
Don't forget that we can have multiple catch blocks on a single try to
handle specific exceptions. That fact could inflate the number of
catches way past finally blocks. Does it seem like most people just
"catch (Exception ex)" as their first option?

On Error Resume Next can easily be implemented as:
try { foo; } finally {}
Sometimes you don't care if there is an exception thrown, like in a
final wrapup routine, you just want to do what you can and get out of
there as fast as possible.
Nov 15 '06 #9
Tony Gravagno <g6***********@sneakemail.com.invalidwrote:

<snip>
On Error Resume Next can easily be implemented as:
try { foo; } finally {}
Sometimes you don't care if there is an exception thrown, like in a
final wrapup routine, you just want to do what you can and get out of
there as fast as possible.
I'm not a VB programmer, but that doesn't sound like it's the same
thing at all. If foo throws an exception, then the above code will
effectively rethrow the exception - it *won't* resume execution on the
next line, which I *thought* was the behaviour of On Error Resume Next.

As I understand it, On Error Resume Next is closer to:

try { foo; } catch {}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 15 '06 #10
Jon Skeet [C# MVP] wrote:
>Tony Gravagno wrote:
>On Error Resume Next can easily be implemented as:
try { foo; } finally {}
>I'm not a VB programmer, but that doesn't sound like it's the same
thing at all. If foo throws an exception, then the above code will
effectively rethrow the exception - it *won't* resume execution on the
next line, which I *thought* was the behaviour of On Error Resume Next.

As I understand it, On Error Resume Next is closer to:

try { foo; } catch {}
Yup yup, I was looking at the comments on Finally and should have
typed Catch. Duh, sorry.
Nov 16 '06 #11
It's more than that:

On Error Resume Next
Statement1
Statement2
Statement3

Translates to
try { Statement1; } catch {}
try { Statement2; } catch {}
try { Statement3; } catch {}

There are very few situations where On Error Resume Next is appropriate. I
use it primarily when I'm configuring the run time environment and some of
the configuration has already been done. Rather than test each
configuration item, I simply don't care if the item is already configured
and reconfiguring it throws an error. That said, you definitely have to
keep the On Error Resume Next modules in VB short and to the point.

C# doesn't have a direct equivalent to "On Error Resume Next".

Mike Ober.

"Tony Gravagno" <g6***********@sneakemail.com.invalidwrote in message
news:j0********************************@4ax.com...
Jon Skeet [C# MVP] wrote:
>>Tony Gravagno wrote:
>>On Error Resume Next can easily be implemented as:
try { foo; } finally {}

>>I'm not a VB programmer, but that doesn't sound like it's the same
thing at all. If foo throws an exception, then the above code will
effectively rethrow the exception - it *won't* resume execution on the
next line, which I *thought* was the behaviour of On Error Resume Next.

As I understand it, On Error Resume Next is closer to:

try { foo; } catch {}

Yup yup, I was looking at the comments on Finally and should have
typed Catch. Duh, sorry.

Nov 16 '06 #12

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

Similar topics

1
by: Christopher.Becker | last post by:
When I'm running my app, I occaisonally receive this error message: PostgreSQL Error Code(1) "could not create socket: An address incompatible with the requested protocol was used" It appears...
20
by: DraguVaso | last post by:
Hi, As a former VB-programmer I'm used to the "on error goto"-errorhandling. I see that in actually all the VB.NET-samples I can fin people use the "Try - catch"-errorhandling. Which of the...
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...
3
by: ton | last post by:
Hi, I've developed some webcontrols in VB, I'm using these in a website project If the webcontrol is getting an error I ll get the message: Server error in '/' application, and than more...
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...
2
by: hdroogendyk | last post by:
Folks: I'm an Access newbie, trying to modify an existing application and running into an error that I don't understand. A tree view control is being loaded from an Access table and the "on...
6
by: neelsfer | last post by:
I have a combobox in a form that looks up records based on this form itself(cyclist tbl).I also add new records to this same form if i cant find the IDNo of a person in this combobox. If i type in...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.