Custom Exception Getting the Stack Trace

  • Thread starter Thread starter Dave Anson
  • Start date Start date
D

Dave Anson

I have a custom exception and I want to write the information to the event
log, including the Stack Trace. I can create the message and write to the
event log no problem, but the Stack Trace is empty.

How do I append the Stack Trace in the custom exception? I can get the
inner exception stack trace from the system exceptions, but how do I get my
own stack trace information.

Thanks in advance

Dave Anson
 
I have a custom exception and I want to write the information to the
event log, including the Stack Trace. I can create the message and write
to the event log no problem, but the Stack Trace is empty.

You need to post a concise-but-complete example of code that reliably
demonstrates the problem.

Assuming your exception inherits Exception, the stack trace property
should be correctly initialized. Normally, it would be. So either you
have some unusual scenario that for some reason causes the stack trace to
not be set, or you are misinterpreting the results of whatever code you're
running.

Only by showing us what exactly you're doing that fails can anyone tell
you how to fix it.

Pete
 
You need to post a concise-but-complete example of code that reliably
demonstrates the problem.

Assuming your exception inherits Exception, the stack trace property
should be correctly initialized. Normally, it would be. So either
you have some unusual scenario that for some reason causes the stack
trace to not be set, or you are misinterpreting the results of
whatever code you're running.

Only by showing us what exactly you're doing that fails can anyone
tell you how to fix it.

Pete

Ok I'll take another look at my code. I expected, that it should display
the stack information I need, as it does inherit from System.Exception.

Either way I'll post the problem or solution if i find one. Thanks.
 
You need to post a concise-but-complete example of code that reliably
demonstrates the problem.

Assuming your exception inherits Exception, the stack trace property
should be correctly initialized. Normally, it would be. So either
you have some unusual scenario that for some reason causes the stack
trace to not be set, or you are misinterpreting the results of
whatever code you're running.

Only by showing us what exactly you're doing that fails can anyone
tell you how to fix it.

Pete

OK. Looks like a schoolboy error. I was calling the StackTrace I'd added to
another my custom logging, but I hadn't set it in my constructor. Hence the
reason it was empty :( Sorry about that, and thanks for the reply.
 
Back
Top