473,756 Members | 6,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7227
On Sat, 01 Dec 2007 22:18:46 -0800, Dave Anson
<da********@jaz zthecat.co.ukwr ote:
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*********@nn owslpianmk.comw rote in
news:op******** *******@petes-computer.local:
On Sat, 01 Dec 2007 22:18:46 -0800, Dave Anson
<da********@jaz zthecat.co.ukwr ote:
>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.Exceptio n.

Either way I'll post the problem or solution if i find one. Thanks.
Dec 2 '07 #3
"Peter Duniho" <Np*********@nn owslpianmk.comw rote in
news:op******** *******@petes-computer.local:
On Sat, 01 Dec 2007 22:18:46 -0800, Dave Anson
<da********@jaz zthecat.co.ukwr ote:
>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
2515
by: Andy Fish | last post by:
Hi, in my c# code I have something like this: try { ... } catch (Exception ex) { ... throw ex; }
1
1432
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 does this? Thanks
1
2821
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 control? thanks
3
24523
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 understand the Stack Trace, but I want to understand the stack trace so can somebody please explain it to me or point me to something that will Thanks Jeremy
2
4389
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
6488
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 signature for method), is this possible without exception-wrapping the guts of each method? I can see how to get parameter values out of MethodInfo, but can't see how to do it without doing something like adding 7 lines to each method, taking...
3
3407
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 exception constructors? I've noticed that, f.ex., ArgumentException accepts null arguments without raising ArgumentNullException. Obviously, if nothing is to be supplied to the exception constructor, the default constructor should
5
2059
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 just where. Although I'm in quite a self-congratulatory mood right now, in the future, I feel like I could save a lot of time by coercing the interpreter to spew forth method calls to stderr. Is this possible?
3
7726
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 std::bad_alloc exception if memory could not be allocated. I have never handled the bad_alloc, so, what I expect here is a stack trace from windows showing the excact location where the exception was thrown. But, to my surprise it gives only the windows ...
0
9384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9973
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9779
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8645
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5069
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5247
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2612
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.