We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

catching method and line number in exception

andremara
andremara asked
on
Medium Priority
481 Views
Last Modified: 2012-05-11
Hi all,
I have a webservice written in C#.NET on VS2008, with framework 3.5. I'm catching errors in my webservice with try/catch block. The catch does something like this:

catch(Exception ex)
{
strStatus = "Problem in xyz program"
strStatus+=ex.Message;
return strStatus;
}

What I'd like is to return the exact method and line number that caused the problem. Is that possible? I don't want to chase things like "object not set to instance of an object" anymore!

Thank you
Andre
Comment
Watch Question

Director
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks. The ex.StackTrace method is very helpful and I'll use that.


By the way, I only got one occurrence of the 'object not set...' error, but I was thrown since my code worked great here but errored at the client. Once I did Build CLEAN, I also got the error here and was able to track it down. Turns out that because I upgraded this code from VS2003, something didn't update behind the scenes in VS2008 and somehow it was using older code for one of my .cs files.

All's good now. Thanks for such fast reply.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
dale_burrell answered in detail and it worked. After I used his info to solve it, Databoks then gave a great answer that was very concise and targeted, although a bit less detail, which is why more points for dale. thanks to both!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.