471,350 Members | 1,450 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

"On Error Resume Next" in C#

esimond
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...
they DO are some cases where the VB "On Error Resume Next" would be great and would bring so much clarity in the code...

Figure out when you have to retrieve values from the registry or a DB and
default or blank values would be OK in case of error.


Well... the question now :

How to easily replace the "On Error Resume Next" in C# ?

Thanks in advance for your help and your precious time,

Eman.


.
Jun 9 '07 #1
4 4850
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...
they DO are some cases where the VB "On Error Resume Next" would be great and would bring so much clarity in the code...

Figure out when you have to retrieve values from the registry or a DB and
default or blank values would be OK in case of error.


Well... the question now :

How to easily replace the "On Error Resume Next" in C# ?

I miss the "Resume Next" too.... Soooo useful to keep the flow of the expected flow if I may say :)


Thanks in advance for your help and your precious time,

Eman.
Jun 9 '07 #2
Difficult one ?

Yes, how to easily re-branch to the flow of the sub from a catch block ???

Example : You must retrieve numerous value and don't want to surround each and every single line with a try / catch {} statment.

Any beautiful solution out there ?


Thanks in advance, as it's always good to know :)

Happy programming !
Emmanuel


.
Jun 9 '07 #3
kenobewan
4,871 Expert 4TB
I guess debugging would help. Remember you can use try catch on blocks of code and not on every line. I believe try catch is good programming around things that can fail like db connections, the rest you should debug. HTH.

BTW - multiple posting is against site rules.

MODERATOR
Jun 10 '07 #4
Just use the following...

try
{
//put you code here
}
catch
{
//do nothing if error occurs
}

The try catch block works great. It will work just like "On Error Resume Next"

Example...

for(int row = 0; row < rowCount; row++)
{
try
{
myDataGrid1.UnSelect(row);
}
catch
{
//do nothing if index out of range error occurs
}
}
Aug 15 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Rudy Ray Moore | last post: by
20 posts views Thread by DraguVaso | last post: by
11 posts views Thread by Maxwell2006 | last post: by
2 posts views Thread by Jolie Chen | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.