Is there a way to turn off error handling in C# 
Author Message
 Is there a way to turn off error handling in C#

There must be, VB.NET does it with On Error Goto 0/On
Error Resume Next.  I understand this is a support
statement for legacy code, but still, it had its purpose.

Also, is there any equivalent to VB's Resume after
processing an error in C#?

Jeff Ulrich



Sat, 21 May 2005 04:04:22 GMT  
 Is there a way to turn off error handling in C#


Quote:
> There must be, VB.NET does it with On Error Goto 0/On
> Error Resume Next.  I understand this is a support
> statement for legacy code, but still, it had its purpose.

> Also, is there any equivalent to VB's Resume after
> processing an error in C#?

No, and for very, very good reasons :)

What is it your trying to do? Perhaps we can recommend a
better error handling framework.

-c



Sat, 21 May 2005 04:10:40 GMT  
 Is there a way to turn off error handling in C#
Its not good programming practice to use those deprecated vb6 statements...


Quote:
> There must be, VB.NET does it with On Error Goto 0/On
> Error Resume Next.  I understand this is a support
> statement for legacy code, but still, it had its purpose.

> Also, is there any equivalent to VB's Resume after
> processing an error in C#?

> Jeff Ulrich



Sat, 21 May 2005 04:14:39 GMT  
 Is there a way to turn off error handling in C#
It sure wasn't good in VB6, and it's definately not good in C#.

I can show you reams of code that has all sorts of hidden errors
in it. It has been modified by so many people over such a long
period of time and if you remove the On Error Resume Next, stuff
actually breaks because of the de-facto conditional processing
the errors create.

If x = y Then? Nah!

On Error Resume Next
If x = y Err.Raise

That'll fix 'em!

-c


Quote:
> Its not good programming practice to use those deprecated vb6
statements...



> > There must be, VB.NET does it with On Error Goto 0/On
> > Error Resume Next.  I understand this is a support
> > statement for legacy code, but still, it had its purpose.

> > Also, is there any equivalent to VB's Resume after
> > processing an error in C#?

> > Jeff Ulrich



Sat, 21 May 2005 04:23:30 GMT  
 Is there a way to turn off error handling in C#
Hi Chad,

Otherwise known as "nailing the corpse upright"!

Regards,

Mark


It sure wasn't good in VB6, and it's definately not good in C#.

I can show you reams of code that has all sorts of hidden errors
in it. It has been modified by so many people over such a long
period of time and if you remove the On Error Resume Next, stuff
actually breaks because of the de-facto conditional processing
the errors create.

If x = y Then? Nah!

On Error Resume Next
If x = y Err.Raise

That'll fix 'em!

-c


Quote:
> Its not good programming practice to use those deprecated vb6
statements...



> > There must be, VB.NET does it with On Error Goto 0/On
> > Error Resume Next.  I understand this is a support
> > statement for legacy code, but still, it had its purpose.

> > Also, is there any equivalent to VB's Resume after
> > processing an error in C#?

> > Jeff Ulrich



Sat, 21 May 2005 05:08:35 GMT  
 Is there a way to turn off error handling in C#
The ONLY time that On Error Resume Next was permissible in VB6 was something
like this:

Dim ErrCode As Long

On Error Resume Next
    CallFunctionWithError Param1, Param2
    ErrCode = Err.Number
On Error Goto 0
If ErrCode <> 0 Then
    ....

In other words, you want to check for errors on a particular line without
jumping.  That's it!  Subverting error handling in any other way is
dangerous, and most probably wrong.

And yes, I have seen code where every function began with "On Error Resume
Next."  This was done to prevent the application from crashing, since errors
were simply ignored.  What ended up happening, though, is that the program
was completely riddled with bugs.  It did not function properly, and ended
up having numerous GPFs, caused by libraries being called with totally wild
parameters.  And to make matters worse, you couldn't even debug the thing
because the VB IDE won't trap errors after a Resume Next statement!

If your code is currently using On Error Resume Next in any other way than
what I have described above, remove the On Error Resume Next lines and fix
the design.  Seriously.  It's not just bad programming practice, it's REALLY
bad programming practice.  And dangerous.

Using C#:

try
{
    CallFunctionWithError(param1, param2);

Quote:
}

catch(JustTheExceptionIAmInterestedIn e)
{
    HandleTheException();

Quote:
}

That is proper programming practice.  It makes your exception handling very
specific and tracable.  And readable.

To subvert all Exception handling in a function, you will need to put
Try/Catch around every statement, catch Exception, and ignore.  Does this
look stupid to you?  It should.  It is the equivalent of what is going on
with the On Error Resume Next statement.

try{DoSomething();}catch(Exception e){}
try{DoSomethingElse();}catch(Exception e){}
try{A = GetSomeObject();}catch(Exception e){}
try{B = DoSomethingWith(A);}catch(Exception e){}
try{C = DoSomethingWith(B);}catch(Exception e){}

What happens if A is null?  What about B?  Are there side effects in later
statements if previous statements fail?  BAD!  BAD! BAD!


Quote:
> There must be, VB.NET does it with On Error Goto 0/On
> Error Resume Next.  I understand this is a support
> statement for legacy code, but still, it had its purpose.

> Also, is there any equivalent to VB's Resume after
> processing an error in C#?

> Jeff Ulrich



Tue, 24 May 2005 07:16:18 GMT  
 Is there a way to turn off error handling in C#


Quote:
> The ONLY time that On Error Resume Next was permissible in VB6 was
something
> like this:

> Dim ErrCode As Long

> On Error Resume Next
>     CallFunctionWithError Param1, Param2
>     ErrCode = Err.Number
> On Error Goto 0
> If ErrCode <> 0 Then

You should say "logically permissible" or "should be permissible"
because
there's nothing in the language that prevents you from being stupid
with On Error Resume Next and I have a whole VSS database full of code
that illustrates it at the place where I work :)

Quote:
> In other words, you want to check for errors on a particular line
without
> jumping.  That's it!  Subverting error handling in any other way is
> dangerous, and most probably wrong.

That would be the smart thing to do. Unfortunately, VB6 and good
programming practice rarely coincide.

Quote:
> And yes, I have seen code where every function began with "On Error
Resume
> Next."  This was done to prevent the application from crashing, since
errors
> were simply ignored.  What ended up happening, though, is that the
program
> was completely riddled with bugs.  It did not function properly, and
ended
> up having numerous GPFs, caused by libraries being called with totally
wild
> parameters.  And to make matters worse, you couldn't even debug the
thing
> because the VB IDE won't trap errors after a Resume Next statement!

Yep. I've seen code where control flow was regulated by errors being
thrown and fancy On Error Resume Next tricks allowing certain code
to continue, etc.

<SNIP>

-c



Tue, 24 May 2005 07:27:06 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Ways of turning echo off ... off

2. turning Exception Handling off

3. Power On/Off and Turn off screen?

4. turn off debugging slop area in VC++ IDE ?

5. How to turn off file watcher

6. turning off run time checks

7. How do I turn off the TaskList

8. Turning off or tracking specific optimizations

9. How do I turn off all form and mouse cursor updates

10. turn off my Computer

11. Selectively Turn Off Xml Docs

12. Turning off Vert Scroll bar on a WinForm

 

 
Powered by phpBB® Forum Software