Re: Catching generic exceptions

Tech-Archive recommends: Speed Up your PC by fixing your registry





it sounds reasonable. Partly I just wanted the ability to log what the error was that occurred. But, it is a useful tool
even though I have found a few of the rules which are just wrong for what I am doing and they have helped to unearth a
few bugs which would have been difficult to find. So, I plan to get the number of errors to a workable number so I can
continue to use it.


Thanks for the input it is interesting to hear of other peoples experience with FxCop.

Sorry I have been rather late in replying. Once I started working on something else I didn't really get chance to reply
sooner.


Steve




On Mon, 14 Nov 2005 21:35:16 +0100, "Michael H?hne" <michael.hoehne@xxxxxxxxxxxxx> wrote:

>>>I do not understand what they expect you to do - ignore unexpected errors?
>
>Well, depending on the type of code where the exception is thrown, the
>answer may be yes. I think that the FxCop warning states somethng like "it
>is usually ok to catch System.Exception in UI applications", because you
>have to display the exception in a user friendly way. However, if you catch
>exceptions in a other pieces of code that are non-GUI applications or do not
>provide any error logging, any unexpected exception should be propagated to
>the caller. The first caller in the call stack then is responsible to
>display the exception message or log it to the event log.
>
>I think that it's nearly impossible to conform to all rules made by FxCop,
>though some of them are pretty good to find code that can be enhanced. In my
>opinion the best way to deal with such warnings is to split your code in
>smaller pieces, so that the UI applications (or whatever application it is
>making the first call to a method that may throw the exception) only contain
>UI-related stuff and all of the needed processing is done in separate class
>libraries. This allows you to ignore the specific warnings only in the
>projects where it makes sense, but you can go on to keep them in other
>projects. However this adds some extra cost to your development. I tried
>FxCop and decided to not use it anymore because it overcomplicates
>development, though I sometimes launch it to find some places I forgot (like
>string constants that should go into resource files, because I usually have
>to write localizable applications).
>
>Michael
>
>"steve bull" <bullsj@xxxxxxxxxxx> schrieb im Newsbeitrag
>news:dep4Q=Cl5xj58QlXTORQBg2nHZm8@xxxxxxxxxx
>>
>>
>> I realize I can catch a generic exception but FxCop - Microsoft's
>> standards as I understand - generates a "Do not catch general
>> exception types" error/warning. I do not understand what they expect you
>> to do - ignore unexpected errors?
>>
>>
>>
>>
>>
>>
>> On 14 Nov 2005 11:40:27 -0800, "BravesCharm" <mastrauckas@xxxxxxxxx>
>> wrote:
>>
>>>try
>>>{
>>>//code
>>>}
>>>catch(Exception e)
>>>{
>>>// will catch ALL exceptions.
>>>}
>>
>

.



Relevant Pages

  • Re: FxCop does anyone use it ?
    ... For instance it founds out if you catch Exception if you could have ... >the same time we developed our framework, so we find "new" warnings on old ... Internal MS code breaks many guidelines. ... We could never have complied to so many guidelines without FxCop. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: FxCop being a bit OTT?
    ... Dave wrote: ... 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 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. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Minimum permissions for Microsoft Exception Application Block
    ... FxCop plug-ins that utilize its call graph and other analysis ... > The minimum permissions have been identified for other application blocks ... > permissions should be for the exception block? ... >> Is there a tool that would examine my assemblies in a Visual Studio ...
    (microsoft.public.dotnet.security)
  • Localizing text in an exception.
    ... I am running the code for a code assembly through FXCop here and it seems to ... FXCop says that I should be grabbing the text from a string resource so that ... exception text most likely to only be seen by a developer. ... and take the time localize my exception strings into other languages? ...
    (microsoft.public.dotnet.general)
  • Re: NT AUTHORITYNetwork Service cant write to .NET Directory?
    ... thats how ASP.NET works - pages are compiled to classes, these classes go into assemblies and these assemblies have to be stored somewhere. ... Developing More Secure Microsoft ASP.NET 2.0 Applications ... Exception Details: System.Web.HttpException: The current identity ... compilationSection) +3482379 ...
    (microsoft.public.dotnet.framework.aspnet.security)