-1

I'm pretty new to .net so my knowledge is pretty limited in many areas.

I'm creating a website at the moment, and have created a few static methods to help me out - here's an example:

 public static void ThrowNull<T>(this T obj, string param) where T : class { if (param.IsNullOrEmpty()) Throw<ArgumentException>("Undefined param!"); if (obj.IsNull()) Throw<ArgumentNullException>(param); } 

I use it as a parameter guard in other methods, calling like this: myVar.ThrowNull("myVar");

The Throw method referred to above looks like this:

 static void Throw<E>(string message) where E : Exception { throw Activator.CreateInstance(typeof(E), message) as E; } 

This all works great for testing but I want to be able to log details that occur from users. How do I get stack trace information from this point?

Any advice appreciated.

4
  • why can't u use logging framework ? Log4Net, ELMAH Commented Feb 15, 2013 at 14:43
  • I agree with Ravi, you should check Log4Net. It logs everything you want. Commented Feb 15, 2013 at 14:46
  • I don't know why this has been downvoted. It isn't a duplicate because I didn't ask how to perform error handling, I asked specifically how I got the stacktrace from the point in my code. Commented Feb 15, 2013 at 15:40
  • @Kami - I'll take a look at Log4Net. Commented Feb 15, 2013 at 15:41

1 Answer 1

0
Exception newException = Activator.CreateInstance(typeof(E), message) as E; <Something?>newException.StackTrace throw newException; 
Sign up to request clarification or add additional context in comments.

2 Comments

what does Something refer to?
Whatever it is you want to do with the stack trace... (which is a string btw)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.