473,382 Members | 1,396 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,382 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 5075
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.