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