On Error Resume Next
-
Hi, I would really not recommend you to use "On Error Resume Next", but if you really need it though you can see this article for a solution: http://www.dotnetfunda.com/articles/article168.aspx[^] A very basic implementation in C# that does the same would be:
try { foo; } catch {}
-
Hello Everybody, As you know In vb.net or vb6 the On Error Resume Next is use to error handling in a function or procedure. In C# have any one for handling error? Best Regard
If you can think then I Can.
-
Hello Everybody, As you know In vb.net or vb6 the On Error Resume Next is use to error handling in a function or procedure. In C# have any one for handling error? Best Regard
If you can think then I Can.
On Error Resume Next was an abortion of a solution, used to help complete idiots make an even bigger mess of things than they had started with. What it does is hide errors. Not fix them, not get rid of them, just hide them. Until they become so huge they corrupt your data, or loose hours of user work. Imagine if you will: as simple index error:
string[] veryValuableDataFromUsers = new string[10];
veryValuableDataFromUsers [10] = myUserTextBox.Text;
foreach (string data in veryValuableDataFromUsers)
{
SaveMyData(data);
}Now, if you run this as is, an exception will be thrown when you try to access array element 10: because the array elements run from 0 to 9 inclusive. You are told what the problem is, you can can fix it in testing, all is fine. If you had On Error Resume Next, what happens? No error. the bad index is ignored, no problem occurs. Until the user tries to find his data, anyway. At which point there are two problems: 1) Very annoyed user, with possibly crucial and not recoverable information lost. 2) Bug to fix, with no idea at all of how the data came to be lost. You may even blame the idiot user for "not saving it" in the first place. 100,000 lines of code to find the problem in. Don't do it. Exceptions are there to tell you there is a problem, and let you deal with it. Don't use empty catch blocks. Log exceptions in production if you can't deal with them - that way you at least have a record of what happened when you come to fix it. But do try to handle errors correctly before they become a major problem.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
On Error Resume Next was an abortion of a solution, used to help complete idiots make an even bigger mess of things than they had started with. What it does is hide errors. Not fix them, not get rid of them, just hide them. Until they become so huge they corrupt your data, or loose hours of user work. Imagine if you will: as simple index error:
string[] veryValuableDataFromUsers = new string[10];
veryValuableDataFromUsers [10] = myUserTextBox.Text;
foreach (string data in veryValuableDataFromUsers)
{
SaveMyData(data);
}Now, if you run this as is, an exception will be thrown when you try to access array element 10: because the array elements run from 0 to 9 inclusive. You are told what the problem is, you can can fix it in testing, all is fine. If you had On Error Resume Next, what happens? No error. the bad index is ignored, no problem occurs. Until the user tries to find his data, anyway. At which point there are two problems: 1) Very annoyed user, with possibly crucial and not recoverable information lost. 2) Bug to fix, with no idea at all of how the data came to be lost. You may even blame the idiot user for "not saving it" in the first place. 100,000 lines of code to find the problem in. Don't do it. Exceptions are there to tell you there is a problem, and let you deal with it. Don't use empty catch blocks. Log exceptions in production if you can't deal with them - that way you at least have a record of what happened when you come to fix it. But do try to handle errors correctly before they become a major problem.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Well us "idiots" had to use on error resume next when writing vb6 (and before) and vbscript in asp as it was our only means of catching an error due to object creation issues, etc. While it certainly opens itself up to what your refer to...if you never were "forced" to use it even in its intented purpose... not sure "idiots" apply in all cases.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
-
Well us "idiots" had to use on error resume next when writing vb6 (and before) and vbscript in asp as it was our only means of catching an error due to object creation issues, etc. While it certainly opens itself up to what your refer to...if you never were "forced" to use it even in its intented purpose... not sure "idiots" apply in all cases.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
No you are right, "idiots" was a little over the top. :-D The idiots were the designers who thought it would be a good idea in the first place! I had no problem with
On Error Goto
, it was the inclusion ofresume next
as a specific way to ignore any problem which did occur which got my back up. Having been raised with FORTRAN compilers which had a defaultOn Error Resume Next
in that they did no error checking whatsoever (and would allow you to declare a character variable and use it as a four dimensional array of floats) I saw what damage a lack of error checking can do. It was a retrograde step to allow novices in particular to easily disable error checking with a single line of code.Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
No you are right, "idiots" was a little over the top. :-D The idiots were the designers who thought it would be a good idea in the first place! I had no problem with
On Error Goto
, it was the inclusion ofresume next
as a specific way to ignore any problem which did occur which got my back up. Having been raised with FORTRAN compilers which had a defaultOn Error Resume Next
in that they did no error checking whatsoever (and would allow you to declare a character variable and use it as a four dimensional array of floats) I saw what damage a lack of error checking can do. It was a retrograde step to allow novices in particular to easily disable error checking with a single line of code.Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Hello Everybody, As you know In vb.net or vb6 the On Error Resume Next is use to error handling in a function or procedure. In C# have any one for handling error? Best Regard
If you can think then I Can.
-
Hi, I would really not recommend you to use "On Error Resume Next", but if you really need it though you can see this article for a solution: http://www.dotnetfunda.com/articles/article168.aspx[^] A very basic implementation in C# that does the same would be:
try { foo; } catch {}
Such a good answer because of the question, but such a bad answer because I hate to see empty try-catches... I'm now in an argument with myself on whether to vote up or down... :)
I wasn't, now I am, then I won't be anymore.
-
Hello Everybody, As you know In vb.net or vb6 the On Error Resume Next is use to error handling in a function or procedure. In C# have any one for handling error? Best Regard
If you can think then I Can.
If you can narrow down the affected code to a line or two, then the following VB code:
On Error Resume Next
Foo()can be converted to:
try
{
Foo();
}
catch
{
//ignore exceptions
}For longer code blocks, you'll have to use a separate try/empty catch for each single line of code.
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com
modified on Tuesday, January 18, 2011 4:42 PM
-
Well us "idiots" had to use on error resume next when writing vb6 (and before) and vbscript in asp as it was our only means of catching an error due to object creation issues, etc. While it certainly opens itself up to what your refer to...if you never were "forced" to use it even in its intented purpose... not sure "idiots" apply in all cases.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous