FxCop complains every time I catch System.Exceptio n.
I don't see the value in trying to catch every possible exception type
(or even figuring out what exceptions can be caught) by a given block
of code, when System.Exceptio n seems to get the job done for me.
My application is an ASP.Net intranet site. When I catch an exception,
I log the stack trace and deal with it, normally by displaying an error
page to the user.
What do I gain by catching a specific exception?
Is there any "easy" way to figure out the possible exceptions that
could be thrown by a given block of code?
Pretty much any block of code that interacts w/ the database and
databinds some information could throw a who slew of possible
exceptions. Does anyone really list out every exception type that
could be thrown in this sitution, as FxCop is saying I should? 7 2339
cmay wrote: FxCop complains every time I catch System.Exceptio n.
I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block of code, when System.Exceptio n seems to get the job done for me.
My application is an ASP.Net intranet site. When I catch an exception, I log the stack trace and deal with it, normally by displaying an error page to the user.
What do I gain by catching a specific exception?
If the point of catching an exception is to report it to the user,
then catching System.Exceptio n is completely appropriate.
If the point of catching an exception is to handle it, you should
be more specific.
Here's an example. You call a third-party subroutine that reads all
of the transactions for a given date and calculates the average.
Unfortunately that routine does not properly handle dates where no
transactions were processed; it gets a "division by 0" error. You
can still call the subroutine, but then you trap the divide-by-0
error and handle it by setting the average transaction amount to 0.
Is there any "easy" way to figure out the possible exceptions that could be thrown by a given block of code?
Ideally, read the documentation that came with that block of code.
Otherwise, the only way I'm aware of is to test the heck out of it...
and then still trap System.Exceptio n so that you can nicely report
errors you aren't prepared to handle directly.
Pretty much any block of code that interacts w/ the database and databinds some information could throw a who slew of possible exceptions. Does anyone really list out every exception type that could be thrown in this sitution, as FxCop is saying I should?
If the response is just to report "an exception occurred," you don't
want to get more specific.
My $0.02
Ok sounds like you and I am pretty much on the same page.
I DO have instances where I know that specific exceptions can occurr,
and I trap those specifically and deal with them.
But there are lots of times when I throw in a try / catch for blocks of
code when I am not sure how they will break, if ever, or if I don't
really all that much if they do break, just so long as they don't crash
the rest of the application.
The more I was reading into it, it looks like FxCop is trying to treat
my code as if I am going to deliver it to a 3rd party who is going to
need deatiled exceptions from me. Instead, I am the component
developer and the component consumer, so when I get an exception, I
don't need the component to throw detailed exceptions so much, because
I am reporting those exceptions and I can go in and fix the components,
or add more detailed error trapping when needed.
Generally you can find the specific exceptions a particular object throws in
the same name space the object is located.
"cmay" wrote: Ok sounds like you and I am pretty much on the same page.
I DO have instances where I know that specific exceptions can occurr, and I trap those specifically and deal with them.
But there are lots of times when I throw in a try / catch for blocks of code when I am not sure how they will break, if ever, or if I don't really all that much if they do break, just so long as they don't crash the rest of the application.
The more I was reading into it, it looks like FxCop is trying to treat my code as if I am going to deliver it to a 3rd party who is going to need deatiled exceptions from me. Instead, I am the component developer and the component consumer, so when I get an exception, I don't need the component to throw detailed exceptions so much, because I am reporting those exceptions and I can go in and fix the components, or add more detailed error trapping when needed.
Ok sounds like you and I am pretty much on the same page.
I DO have instances where I know that specific exceptions can occurr,
and I trap those specifically and deal with them.
But there are lots of times when I throw in a try / catch for blocks of
code when I am not sure how they will break, if ever, or if I don't
really all that much if they do break, just so long as they don't crash
the rest of the application.
The more I was reading into it, it looks like FxCop is trying to treat
my code as if I am going to deliver it to a 3rd party who is going to
need deatiled exceptions from me. Instead, I am the component
developer and the component consumer, so when I get an exception, I
don't need the component to throw detailed exceptions so much, because
I am reporting those exceptions and I can go in and fix the components,
or add more detailed error trapping when needed.
If you are just reporting the exception, you will only want to catch
Exception at the highest level in your program. In that case, your
"components " should never catch it. It is assumed that your components
will be used by an application (which you also create). The benefit of
structure exception handling is that the exceptions will bubble up, so
that you only have to deal with them when you need to. If your
components do not know how to recover from an error, don't have them
catch exceptions at all. Leave it up to the "top" level application
(the closes to the user) to catch all exceptions and log/report them.
Joshua Flanagan http://flimflan.com/blog
cmay wrote: Ok sounds like you and I am pretty much on the same page.
I DO have instances where I know that specific exceptions can occurr, and I trap those specifically and deal with them.
But there are lots of times when I throw in a try / catch for blocks of code when I am not sure how they will break, if ever, or if I don't really all that much if they do break, just so long as they don't crash the rest of the application.
The more I was reading into it, it looks like FxCop is trying to treat my code as if I am going to deliver it to a 3rd party who is going to need deatiled exceptions from me. Instead, I am the component developer and the component consumer, so when I get an exception, I don't need the component to throw detailed exceptions so much, because I am reporting those exceptions and I can go in and fix the components, or add more detailed error trapping when needed.
Generally you can find the specific exceptions a particular object throws in
the same name space the object is located.
"cmay" wrote: Ok sounds like you and I am pretty much on the same page.
I DO have instances where I know that specific exceptions can occurr, and I trap those specifically and deal with them.
But there are lots of times when I throw in a try / catch for blocks of code when I am not sure how they will break, if ever, or if I don't really all that much if they do break, just so long as they don't crash the rest of the application.
The more I was reading into it, it looks like FxCop is trying to treat my code as if I am going to deliver it to a 3rd party who is going to need deatiled exceptions from me. Instead, I am the component developer and the component consumer, so when I get an exception, I don't need the component to throw detailed exceptions so much, because I am reporting those exceptions and I can go in and fix the components, or add more detailed error trapping when needed.
If you are just reporting the exception, you will only want to catch
Exception at the highest level in your program. In that case, your
"components " should never catch it. It is assumed that your components
will be used by an application (which you also create). The benefit of
structure exception handling is that the exceptions will bubble up, so
that you only have to deal with them when you need to. If your
components do not know how to recover from an error, don't have them
catch exceptions at all. Leave it up to the "top" level application
(the closes to the user) to catch all exceptions and log/report them.
Joshua Flanagan http://flimflan.com/blog
cmay wrote: Ok sounds like you and I am pretty much on the same page.
I DO have instances where I know that specific exceptions can occurr, and I trap those specifically and deal with them.
But there are lots of times when I throw in a try / catch for blocks of code when I am not sure how they will break, if ever, or if I don't really all that much if they do break, just so long as they don't crash the rest of the application.
The more I was reading into it, it looks like FxCop is trying to treat my code as if I am going to deliver it to a 3rd party who is going to need deatiled exceptions from me. Instead, I am the component developer and the component consumer, so when I get an exception, I don't need the component to throw detailed exceptions so much, because I am reporting those exceptions and I can go in and fix the components, or add more detailed error trapping when needed. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: mfraser |
last post by:
What is the difference between System.SystemException and
System.Exception?
|
by: CSharpX |
last post by:
I have the following code and when the exception is raised the OS displays a nasty Stop dialog box
it says an unhandled exception occured, gives 3 buttons to click details, contintue Quit... i do not want this ugly thing to display, what am i missing from the code below? am i not catching that exception and displaying my own error message? so why is the other one coming up after mine
public bool isInteger(string str
int i=0
bool...
|
by: Selen |
last post by:
I am using asp.net c#...I am adding a field to cystal report but I get error
Exception of
type System.Exception was thrown. How can I solve this error...When I insert
a field from another table I dont get error...
Thanks...
|
by: Ivan A. |
last post by:
Hi
Is there any method to change System. Exception. Message property in derived
exception's constructor? I need runtime class' information to initialize
this property, but it's readonly.
Thaks.
|
by: Selen |
last post by:
I am using asp.net c#...I am adding a field to crystal report but I get
error
Exception of
type System.Exception was thrown. How can I solve this error...When I insert
a field from another table I dont get error...
Thanks...
| |
by: Ramon de Klein |
last post by:
I try to serialize an exception using the SoapFormatter, but this is a little
bit problematic. The MethodInfo tag of the serialized exception contains &x00
characters (ASCII 0x00) in its serialized data. When the data is deserialized
on the client side the SoapHttpClientProtocol.ReadResponse uses an
XmlTextReader with Normalization switched on. In that case the &x00 character
is not valid and results in the following XmlException:
...
|
by: newscorrespondent |
last post by:
A System.Exception has a Data property that I would like to add data to
before I call my standard exception handler. When in a routine that uses SQL
server I would like to add the
System.Data.SqlClient.SqlConnectionSQLConnection,
System.Data.SqlClient.SqlCommand and System.Data.SqlClient.SqlDataReader
when there is one.
Exception abc = new Exception("abc");
abc.Data.Add("TheConnection",TheConnection);
abc.Data.Add("TheSQLCommand",...
|
by: badfog |
last post by:
I created a VS 2005 site with rdlc files dynamically generated.
All is perfectly running on dev computer but when deployed on iis
server I always have a system.exception after reportviewer assembly
loaded.
I tried on two servers and I have the same problem.
My servers are Windows 2000 Server SP 4 with SQL Server 2000 SP4.
|
by: minhtran |
last post by:
Hi All
I create web page as ASP.NET . The program runs on localhost no problem,but when we upload on server has an error as :
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Exception: File not found
Source Error:
Line 244: Dim j As Integer
Line 245: Dim k As Integer
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |