473,402 Members | 2,055 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,402 software developers and data experts.

C# exceptions

It there any way to attatch the point of creation of an
error which is thrown in an object to the instance that
caused it to be thrown rather than the throw statement?
Nov 15 '05 #1
2 3823
I don't know whether I understand your question.

If you are talking about re-throwing an exception, the exception class does
have an InnerException property that you can use to keep a reference to the
original statment. Also, the exception includes a string representation of
the call stack.
"Ghost" <m.********@dur.ac.uk> wrote in message
news:00****************************@phx.gbl...
It there any way to attatch the point of creation of an
error which is thrown in an object to the instance that
caused it to be thrown rather than the throw statement?

Nov 15 '05 #2
I think I know what you mean. ;-)

You need to create an additional constructor for your custom exception class
which also contains the inner exception, and calls its base class
constructor with the same signature:

I.e.:

public MyException(string message, Exception inner) : base(message, inner)
{}

When you then throw your custom exception make sure you use this constructor
and put the original Exception in as 2nd parameter. The calling app can then
retrieve the full StackTrace from your inner exception.

Hope that makes sense somehow. :-)

Cheers,
Wim Hollebrandse

--
Wimdows Components
..NET components - professional, robust and affordable.
http://www.wimdows.com
--

"Ghost" <m.********@dur.ac.uk> wrote in message
news:11****************************@phx.gbl...
-----Original Message-----
It there any way to attatch the point of creation of an
error which is thrown in an object to the instance that
caused it to be thrown rather than the throw statement?
.


OK perhaps a little unclear - what I require is that when
the custom exception, that I have already created by
extending the ApplicationException class, is thrown in
the code it is done so by a class which is instantiated
in another class. When the code executes however instead
of referencing the instance of the object that caused the
exception it references the object class its self ie the
trace shows a line number with throw new MyException();
instead of the code for the instance that actually caused
the error.

Nov 15 '05 #3

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

Similar topics

21
by: dkcpub | last post by:
I'm very new to Python, but I couldn't find anything in the docs or faq about this. And I fished around in the IDLE menus but didn't see anything. Is there a tool that can determine all the...
26
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
33
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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
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...
0
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...

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.