By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,689 Members | 1,901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,689 IT Pros & Developers. It's quick & easy.

Exception properties

P: n/a
I am trying to create a generic logging component that will accept an
exception object and create a string containing all the properties and their
values available for a specific exception.

My intent here is try to create a generic function that will be able to:

- Take a an object of type Exception...
- Iterate through all the properties the object has...
- Add the property names to a stringbuilder...
- Call each of the properties and get the values...
- Add each of the values to the string builder.

I can get all the basic properties that System.Exception provides (Message,
Source, Inner Exception, Target Site, Stack Trace, etc...) but I would also
like to be bale to get any customer properties provided by the more specific
exceptions and also print them out.

Can anyone point me to a piece of code that will help? I would also like to
be able to print the specifics on custom exceptions that are not part of the
framework but I am thinking that I am not going to be able to get much
deeper than the standard properties provided by the base exception the
custom exception inherits from.

Any ideas out there?

Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Ray Cassick \(Home\)" <rc************@enterprocity.com> wrote in
news:Oo*************@TK2MSFTNGP12.phx.gbl:
Can anyone point me to a piece of code that will help? I would also like
to be able to print the specifics on custom exceptions that are not part
of the framework but I am thinking that I am not going to be able to get
much deeper than the standard properties provided by the base exception
the custom exception inherits from.


Look in MSDN for "reflection".
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
Nov 20 '05 #2

P: n/a
Ray,
I would expect custom Exceptions to override the Exception.ToString method
to include this information in a readable & sensible format for you.

All the exception that I have used from the Framework do this for you, I
would expect any one implementing their own exceptions to also do the same!
Either by overriding Exception.ToString itself or overriding
Exception.Message (which ever made the most sense for the use of the custom
Exception).

Hope this helps
Jay

"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:Oo*************@TK2MSFTNGP12.phx.gbl...
I am trying to create a generic logging component that will accept an
exception object and create a string containing all the properties and their values available for a specific exception.

My intent here is try to create a generic function that will be able to:

- Take a an object of type Exception...
- Iterate through all the properties the object has...
- Add the property names to a stringbuilder...
- Call each of the properties and get the values...
- Add each of the values to the string builder.

I can get all the basic properties that System.Exception provides (Message, Source, Inner Exception, Target Site, Stack Trace, etc...) but I would also like to be bale to get any customer properties provided by the more specific exceptions and also print them out.

Can anyone point me to a piece of code that will help? I would also like to be able to print the specifics on custom exceptions that are not part of the framework but I am thinking that I am not going to be able to get much
deeper than the standard properties provided by the base exception the
custom exception inherits from.

Any ideas out there?

Nov 20 '05 #3

P: n/a
Yeah, I know about that property. I was just trying to get something wrapped
up that would be a bit more standardized and not depend on the person that
designed the exception class.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:#Y**************@TK2MSFTNGP11.phx.gbl...
Ray,
I would expect custom Exceptions to override the Exception.ToString method
to include this information in a readable & sensible format for you.

All the exception that I have used from the Framework do this for you, I
would expect any one implementing their own exceptions to also do the same! Either by overriding Exception.ToString itself or overriding
Exception.Message (which ever made the most sense for the use of the custom Exception).

Hope this helps
Jay

"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:Oo*************@TK2MSFTNGP12.phx.gbl...
I am trying to create a generic logging component that will accept an
exception object and create a string containing all the properties and

their
values available for a specific exception.

My intent here is try to create a generic function that will be able to:

- Take a an object of type Exception...
- Iterate through all the properties the object has...
- Add the property names to a stringbuilder...
- Call each of the properties and get the values...
- Add each of the values to the string builder.

I can get all the basic properties that System.Exception provides

(Message,
Source, Inner Exception, Target Site, Stack Trace, etc...) but I would

also
like to be bale to get any customer properties provided by the more

specific
exceptions and also print them out.

Can anyone point me to a piece of code that will help? I would also like

to
be able to print the specifics on custom exceptions that are not part of

the
framework but I am thinking that I am not going to be able to get much
deeper than the standard properties provided by the base exception the
custom exception inherits from.

Any ideas out there?


Nov 20 '05 #4

P: n/a
Ray,
As Chad stated, you can use Reflection to do what you want.
IMHO doing the exception correctly is the "standardized" part! The person
designing the exception would/should design the exception per standards!

Also won't you be logging duplicate information in most cases? (As most
exception classes are standardized, then you have your code to catch this
info for non-standardized exceptions...)

Or missing information in cases where there was an InnerException?

The following are a couple of articles on Exception Standards:

http://msdn.microsoft.com/library/de...Guidelines.asp

http://msdn.microsoft.com/library/de...rp08162001.asp

Hope this helps
Jay

"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Yeah, I know about that property. I was just trying to get something wrapped up that would be a bit more standardized and not depend on the person that
designed the exception class.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:#Y**************@TK2MSFTNGP11.phx.gbl...
Ray,
I would expect custom Exceptions to override the Exception.ToString method to include this information in a readable & sensible format for you.

All the exception that I have used from the Framework do this for you, I
would expect any one implementing their own exceptions to also do the

same!
Either by overriding Exception.ToString itself or overriding
Exception.Message (which ever made the most sense for the use of the

custom
Exception).

Hope this helps
Jay

"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:Oo*************@TK2MSFTNGP12.phx.gbl...
I am trying to create a generic logging component that will accept an
exception object and create a string containing all the properties and

their
values available for a specific exception.

My intent here is try to create a generic function that will be able to:
- Take a an object of type Exception...
- Iterate through all the properties the object has...
- Add the property names to a stringbuilder...
- Call each of the properties and get the values...
- Add each of the values to the string builder.

I can get all the basic properties that System.Exception provides

(Message,
Source, Inner Exception, Target Site, Stack Trace, etc...) but I would

also
like to be bale to get any customer properties provided by the more

specific
exceptions and also print them out.

Can anyone point me to a piece of code that will help? I would also
like to
be able to print the specifics on custom exceptions that are not part
of the
framework but I am thinking that I am not going to be able to get much
deeper than the standard properties provided by the base exception the
custom exception inherits from.

Any ideas out there?



Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.