Exception Handling

S

steven chong

Hi,

A button event on my page actually triggers a chain of method calls, and
each of these methods has its own try catch statement. The error is
thrown all the way from DataAccess->Business->and subsequently handled
in the Presentation layer.
My problem is, if i do a try catch, the inner exception of the exception
which i get in the presentation layer only shows what happened in
presentation. The bus, and presentation exceptions stacktraces are all lost.
However, if i DO NOT use try catch, and just handle the exceptions in
the web (meaning try catch in button_clicks, page_loads), i get the
entire chain of event leading to the error.
Is this by design (try catch throw statments removes my exception
trace)? My goal is the obtain the entire chain of events, for error
trapping and debugging purposes.

Thanks in advance
 
C

Craig Deelsnyder

Why not recursively look at the inner exception of each inner exception?

Catch ex as Exception
Dim ex2 as Exception = ex.InnerException
Dim ex3 as Exception = ex2.InnerException
Dim ex4 as Exception = ex3.InnerException
....

BTW, this layout of code is very inefficient, but often times necessary.
Doing a lot of try...catches in the same thread of processing is very
intense stack work. If these different levels are of course separate
codebases/libraries, which you normally don't change (perhaps someone else
wrote them or they just sit in a dll), then this is what needs to happen.
Otherwise, try to minimize who catches exceptions, etc. where it makes sense
application-wise. Make sure if you catch and re-throw another exception, it
makes sense, or perhaps it makes sense to let this certain type of exception
bubble naturally, etc.

Just an FYI...
 
S

steven chong

Craig said:
Why not recursively look at the inner exception of each inner exception?

Catch ex as Exception
Dim ex2 as Exception = ex.InnerException
Dim ex3 as Exception = ex2.InnerException
Dim ex4 as Exception = ex3.InnerException
...

BTW, this layout of code is very inefficient, but often times necessary.
Doing a lot of try...catches in the same thread of processing is very
intense stack work. If these different levels are of course separate
codebases/libraries, which you normally don't change (perhaps someone else
wrote them or they just sit in a dll), then this is what needs to happen.
Otherwise, try to minimize who catches exceptions, etc. where it makes sense
application-wise. Make sure if you catch and re-throw another exception, it
makes sense, or perhaps it makes sense to let this certain type of exception
bubble naturally, etc.

Just an FYI...

thanks. i'm now following the rule:
1) only catch exception if you want to handle
2) and only throw exception that you really DO want to throw
3) else just leave it to bubble all the way up
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top