FxCop being a bit OTT?

D

Dave

Hi all,

I'm using FxCop to go through my code and it's showing bad things in my
code. It is saying that you should never ever catch a general exception, and
since in my (apparent) foolishness I'm catching all errors in my user
interface I've got a fair few of these in my code. I'm doing this so that if
a user presses a button if for some reason my code fails the worst case
scenario for the user is either a usefull error message of a generic one
asking them to send in an error log file rather than having the whole
application fall over because I missed a pottential exception.

So... who's right here, FxCop or me? It's possible of course I'm missing
something important...

Dave
 
M

Mark Rae

So... who's right here, FxCop or me?

FxCop is very little more than somebody else's opinion on how they think
your code should be written and structured...

As with all such advice, it's up to you to act on it or not...

I've always viewed FxCop as an interesting exercise - nothing more than
that...

I believe you can turn off the "rules" that you don't agree with... :)
 
D

Dave

Thanks for that. Mostly I was just wondering if there was something I was
missing here. Seemed unlikely but you never know...

Dave
 
J

Jesse Houwing

If you read the documentation for this error, you'll find that they
already make an exception for global exception handling and logging
situations much like you are describing.

Jesse

* Dave wrote, On 23-6-2007 14:07:
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Dave said:
Hi all,

I'm using FxCop to go through my code and it's showing bad things in my
code. It is saying that you should never ever catch a general exception, and
since in my (apparent) foolishness I'm catching all errors in my user
interface I've got a fair few of these in my code. I'm doing this so that if
a user presses a button if for some reason my code fails the worst case
scenario for the user is either a usefull error message of a generic one
asking them to send in an error log file rather than having the whole
application fall over because I missed a pottential exception.

So... who's right here, FxCop or me? It's possible of course I'm missing
something important...

Dave

Even if FxCop is a bit strict, the advice it gives is well founded. You
can of course break the "rules" if you like, but you should make sure
that you know what it's founded on and that you know the alternatives.

In this case there is no reason to catch all exceptions in order to
shelter the users from error messages. Just use the
Application.ThreadException event, which fires whenever a thread ends
with an unhandled exception.
 
D

Dave

Thanks for that but the majority of the errors will be in background threads
which I don't want to terminate on an error (need to free resources, send
error messages over the network, etc). Given my understanding of
Application.ThreadException and Applicatoin.UnhandledException I have to
provide the catch all handlers in each thread individually to be able to do
this.

Dave
 
I

Ian Semmel

Göran Andersson said:
Even if FxCop is a bit strict, the advice it gives is well founded. You
can of course break the "rules" if you like, but you should make sure that
you know what it's founded on and that you know the alternatives.

The problem is that the default settings give so much information, that the
average user (read me) is going to ignore them all. Things like getting a
warning every time you use a string litereal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top