By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,588 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

"On Error Resume Next" in C#

esimond
P: 6
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
Share this Question
Share on Google+
4 Replies


esimond
P: 6
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

esimond
P: 6
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
Expert 2.5K+
P: 4,871
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

P: 1
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.