Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Extracting as much information as possible from an exception

Posted on 2009-05-13
4
Medium Priority
?
157 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 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