473,320 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Exception Handling

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
Nov 17 '05 #1
2 1834
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 Deelsnyder
Microsoft MVP - ASP/ASP.NET
"steven chong" <st**********@gamebox.net> wrote in message
news:3f********@news.tm.net.my...
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

Nov 17 '05 #2
Craig Deelsnyder wrote:
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

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: adi | last post by:
Dear all, This is more like a theoretical or conceptual question: which is better, using exception or return code for a .NET component? I had created a COM object (using VB6), which uses...
6
by: Daniel Wilson | last post by:
I am having exception-handling and stability problems with .NET. I will have a block of managed code inside try...catch and will still get a generic ..NET exception box that will tell me which...
7
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
3
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech...
2
by: tom | last post by:
Hi, I am developing a WinForm application and I am looking for a guide on where to place Exception Handling. My application is designed into three tiers UI, Business Objects, and Data Access...
9
by: C# Learner | last post by:
Some time ago, I remember reading a discussion about the strengths and weaknesses of exception handling. One of the weaknesses that was put forward was that exception handling is inefficient (in...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
4
by: Ele | last post by:
When Exception handling disabled compiler still spits out "C++ exception handler used." Why is that? Why does it ask for "Specify /EHsc"? Thanks! c:\Program Files\Microsoft Visual Studio...
41
by: Zytan | last post by:
Ok something simple like int.Parse(string) can throw these exceptions: ArgumentNullException, FormatException, OverflowException I don't want my program to just crash on an exception, so I must...
1
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.