Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2007

Tip: Looking for answers? Try searching our database.

catching exceptions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bitshift - 29 Aug 2007 14:27 GMT
In many asp.net pages I want to trap for errors, but I often really dont do
anything with the exception object itself, so I get annorying warning
messages when it comes time to build.  So i started changing how i catch
exceptions like so:

try {

...code here
}
catch(Exception) {

//do something here
}

Notice im not creating an explicit exception object, as is the usual cas
like so:
catch (Exception ex) ...

Is it bad (performance wise) to NOT create an explicit exception object like
im doing ?
Niels Ull - 29 Aug 2007 15:40 GMT
> In many asp.net pages I want to trap for errors, but I often really
> dont do anything with the exception object itself, so I get annorying
[quoted text clipped - 14 lines]
> Is it bad (performance wise) to NOT create an explicit exception
> object like im doing ?

If you don't refer to ex, there is no difference what so ever - the generated
code will be exactly the same.
Leaving out ex is just a syntactical way of indicating you won't use it.

By the way, it's very bad style to just eat exceptions like this - it makes
it extremely hard to locate errors.
Peter Duniho - 29 Aug 2007 18:48 GMT
> [...]
> Is it bad (performance wise) to NOT create an explicit exception object like
> im doing ?

No.  In fact, if you don't actually need access to the data within the
Exception, it's a perfectly normal thing to do.

I'd like to temper Niels suggestion that "eating exceptions" is a bad
thing to do, by asking whether the code you posted is literally how you
are catching the exception.  Is it?

If you are catching the base Exception class, then you definitely need
to get the exception instance itself, look at it, and if it's not a kind
of exception that you expected and know how to deal with, rethrow it.

If, on the other hand, the code you posted is just "for example" and in
reality you are catching a specific type of exception, then you should
be fine.  Just make sure that you don't accidentally catch exceptions
that you didn't expect to occur at that point in the code (if you want a
general-purpose catch-all clause, that's fine, but you should treat that
as a severe error and always display some information to the user
reporting the error).

Pete
Patrice - 30 Aug 2007 12:23 GMT
What do you do in the catch clause ? Are you after the finally clause that
allows to perform guaranteed cleanup ?

You may want to explain what you are trying to do (having a global exception
handler that centrally report errors and do only some cleanup at particular
places when needed ???)

--
Patrice

> In many asp.net pages I want to trap for errors, but I often really dont
> do anything with the exception object itself, so I get annorying warning
[quoted text clipped - 16 lines]
> Is it bad (performance wise) to NOT create an explicit exception object
> like im doing ?
Bond - 31 Aug 2007 10:51 GMT
> In many asp.net pages I want to trap for errors, but I often really dont do
> anything with the exception object itself, so I get annorying warning
> messages when it comes time to build.So i started changing how i catch
> exceptions like so:

U need to check whether u had implemented the System.Exception; has
been mentioned or not.
and if still the problem arises the best and the most effective way is
to use debugging functions .
the only thing u need to do is that just select the statement which
rise the error and debug it .
It will show u the show u the execution of program as well as Error
too.....

thank  you.

Jitesh tolar
http://www.intelcs.com/IT-Companies

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.