473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Custom Exception Getting the Stack Trace

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
Dec 2 '07 #1
3 7200
On Sat, 01 Dec 2007 22:18:46 -0800, Dave Anson
<da********@jazzthecat.co.ukwrote:
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
Dec 2 '07 #2
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in
news:op***************@petes-computer.local:
On Sat, 01 Dec 2007 22:18:46 -0800, Dave Anson
<da********@jazzthecat.co.ukwrote:
>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
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.
Dec 2 '07 #3
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in
news:op***************@petes-computer.local:
On Sat, 01 Dec 2007 22:18:46 -0800, Dave Anson
<da********@jazzthecat.co.ukwrote:
>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
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.
Dec 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Andy Fish | last post by:
Hi, in my c# code I have something like this: try { ... } catch (Exception ex) { ... throw ex; }
1
by: BCC | last post by:
I would like to write a small class that will dump out the call stack in the event of an error. Rather than reinvent the wheel, does anyone have any recommendations for free stuff that already...
1
by: Raj Chudasama | last post by:
How can i obtain stack trace and email it to myself? i know when your program catches an exception you can obtain stacktrace but i dont know hot i can have it email it to me. Is this a custom...
3
by: Jeremy | last post by:
While working with ASP.NET I've sometimes encountered errors in my applications, but I've always known exactly why I'm getting the error and have been able to fix it. So I've never needed to...
2
by: Lasse Vågsæther Karlsen | last post by:
If I got the following code: try { // something that might throw an exception } catch (Exception ex) { // Log contents of ex here throw;
2
by: news.microsoft.com | last post by:
Hi all. If I wanted to write something so that, when an exception was thrown, and the stack unwound, the stack trace was captured with the values of the parameters (instead of just the parameter...
3
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own...
5
by: James Stroud | last post by:
Hello All, The built-in mac osx vecLib is segfaulting in some cases--A very fun fact to find out the hard way over two nights of work. I also spent an embarrassing amount of time figuring out...
3
by: Sendil kumar | last post by:
Hi All, Problem Stetement:I have a problem in getting stack trace when I ues std::exception. In my code, I allocate virtual memory for certain kind of processing and will throw the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.