Exception Handling

  • Thread starter Thread starter steven chong
  • Start date Start date
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
 
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...
 
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
 
Back
Top