Solved

Extracting as much information as possible from an exception

Posted on 2009-05-13
4
149 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

929 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now