Solved

Extracting as much information as possible from an exception

Posted on 2009-05-13
4
148 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

6 Experts available now in Live!

Get 1:1 Help Now