473,287 Members | 1,947 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,287 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 47837
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.