473,246 Members | 1,522 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,246 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 5059
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

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

Similar topics

1
by: Luis | last post by:
I use CDO to send an email to users as part of a 'Reset Password' functionality I have on a intranet site. I use: METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB- 00C04FB1625D" NAME="CDO...
0
by: kjr | last post by:
In VB6 I was able to trap and error and if I wanted to ignore the error (e.g. Invalid use of null or InvalidCastException: a db column was null when reading into a variable) I could "Resume Next"...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
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...
10
by: Parasyke | last post by:
I have a form that I choose from a list of database names and a list within a textbox comes up with the computer ID number and an associated (from a table) user name. Is there a way from looking at...
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...
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
by: Irfan12 | last post by:
I am using the following PHP code to force the internet browser to download a media file(e.g, .mp3, .wma), But in this code, there is no resume support in downloading these files. i dont know PHP,...
2
by: Jolie Chen | last post by:
I am learning template programming now, and I wrote the following code #include <iostream> #include "Queue.h" using namespace std; template <typename Tclass QueueItem { public: QueueItem(T...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

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.