Solved

Extracting as much information as possible from an exception

Posted on 2009-05-13
4
150 Views
Last Modified: 2013-11-07
Hi

I am doing some error logging and I want to make sure I extract as much useful information as possible from the exceptions. I don't think, however, that I fully understand exception structure.
For example, why do some exceptions have 'inner exceptions' and others don't. I presume the inner most exception is the most useful one as that is the root cause. How do i get the inner exception? What other information do I need to extract from my exception? Also how do I get the stack trace for an exception?

Many thanks
0
Comment
Question by:andieje
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
ToddBeaulieu earned 500 total points
ID: 24377556
If you catch and exception and wrap in another exception, you end up with an inner exception. This can happen in as many levels as you want. Since you never know how code that's not yours was written, there's no way to know how many levels exist. Therefore, enumerate the inner exceptions if you want them. It's really up to you to decide how you want to deal with this stuff. Start with a simple application and experiment by throwing exceptions from within nested methods (several levels) and see what you get. The stack trace is a property of the exception object caught.  break point in a catch{} and drill into the exception passed in to explore its contents.

try
{
    throw new exception("this is an inner");
}
catch(exception ex)
{
    throw new exception("this is an outer", ex); // <--- ex is the inner.
}
0
 

Author Comment

by:andieje
ID: 24378124
Hi

Thats very helpful. How do I add a breakpoint in a catch block. In vs2005 I select add breakpoint and the only option is break at function. I try adding one anyway and nothing happens when you reach the catch block.

Thanks
0
 
LVL 16

Expert Comment

by:ToddBeaulieu
ID: 24378167
I don't know what you mean by the only option being to add it on  a function. I wonder if you're looking in the tools/options?

If you start a new project, create a function, plug that code into it, select the line you want to break on and HIT f(, you'll have a break point. You can also left click in the margin to the left of the line to toggle the breakpoint, shown by a red circle. You can also STEP INTO the app. Start with a real simple project so you can focus on figuring this problem out.
0
 

Author Closing Comment

by:andieje
ID: 31581107
thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question