?
Solved

Extracting as much information as possible from an exception

Posted on 2009-05-13
4
Medium Priority
?
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
ToddBeaulieu earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 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