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

Enumerate Exceptions

I am trying to log exceptions. It seems like I have to write the code for
each member that I would like to log.
It would be nice to replace this with code to enumerate an exception, but it
seems that exceptions do not have .getEnumerator().

Any ideas?

I would like to replace this:
public void LogNullReferenceException(NullReferenceException
NullReferenceException1)

{

Console.WriteLine(NullReferenceException1.Data);

Console.WriteLine(NullReferenceException1.HelpLink );

Console.WriteLine(NullReferenceException1.InnerExc eption);

Console.WriteLine(NullReferenceException1.Message) ;

Console.WriteLine(NullReferenceException1.Source);

Console.WriteLine(NullReferenceException1.StackTra ce);

Console.WriteLine(NullReferenceException1.TargetSi te);

}

with something like this psuedocode:

public void LogNullReferenceException(NullReferenceException
NullReferenceException1)

{

foreach (MemberInfo myMemberInfo in NullRefereneException1){

Console.WriteLine(myMemberInfo.Name + ":" + myMemberInfo.Value);

}

}


Nov 19 '08 #1
2 1726
"Guitar Dude" <Gu********@discussions.microsoft.comwrote in message
news:B3**********************************@microsof t.com...
[...] this psuedocode:

public void LogNullReferenceException(NullReferenceException
NullReferenceException1)
{
foreach (MemberInfo myMemberInfo in NullRefereneException1){
Console.WriteLine(myMemberInfo.Name + ":" + myMemberInfo.Value);
}
}
using System.Reflection;
....
public void LogNullReferenceException(NullReferenceException
NullReferenceException1)
{
Type t = typeof(NullReferenceException);
foreach (PropertyInfo pi in t.GetProperties())
{
object value = pi.GetValue(NullReferenceException1, null);
Console.WriteLine(pi.Name + ":" + value.ToString());
}
}

Nov 19 '08 #2
Alberto Poblacion wrote:
"Guitar Dude" <Gu********@discussions.microsoft.comwrote in message
news:B3**********************************@microsof t.com...
>[...] this psuedocode:

public void LogNullReferenceException(NullReferenceException
NullReferenceException1)
{
foreach (MemberInfo myMemberInfo in NullRefereneException1){
Console.WriteLine(myMemberInfo.Name + ":" + myMemberInfo.Value);
}
}

using System.Reflection;
...
public void LogNullReferenceException(NullReferenceException
NullReferenceException1)
{
Type t = typeof(NullReferenceException);
Better:

Type t = NullReferenceException1.GetType();

Then you can change the parameter to System.Exception and it will work for
any sort of exception.

Also remember to walk the exception custom data dictionary (I forget what
it's called).
foreach (PropertyInfo pi in t.GetProperties())
{
object value = pi.GetValue(NullReferenceException1, null);
Console.WriteLine(pi.Name + ":" + value.ToString());
}
}

Nov 19 '08 #3

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

Similar topics

5
by: Pekka Niiranen | last post by:
Hi, I have Perl code looping thru lines in the file: line: while (<INFILE>) { ... $_ = do something ... if (/#START/) { # Start inner loop
3
by: Cliff Harris | last post by:
I have an odd question that I'm hoping someone can help with. I simply (or not simply?) need to enumerate through all of the data types in the .Net framework. I do understand that if this is...
5
by: HL | last post by:
Hi, I need to enumerate windows and find the sum of the rect of all the windows of a specific application. In C++, I use the APIs - 'EnumWindows , GetWindowRect and UnionRect to accomplish the...
1
by: smichr | last post by:
I see that there is a thread of a similar topic that was posted recently ( enumerate with a start index ) but thought I would start a new thread since what I am suggesting is a little different. ...
6
by: Gregory Petrosyan | last post by:
Hello! I have a question for the developer of enumerate(). Consider the following code: for x,y in coords(dots): print x, y When I want to iterate over enumerated sequence I expect this to...
2
by: eight02645999 | last post by:
hi, i am using python 2.1. Can i use the code below to simulate the enumerate() function in 2.3? If not, how to simulate in 2.1? thanks from __future__ import generators def...
8
by: Dustan | last post by:
Can I make enumerate(myObject) act differently? class A(object): def __getitem__(self, item): if item 0: return self.sequence elif item < 0: return self.sequence elif item == 0: raise...
21
by: James Stroud | last post by:
I think that it would be handy for enumerate to behave as such: def enumerate(itrbl, start=0, step=1): i = start for it in itrbl: yield (i, it) i += step This allows much more flexibility...
12
by: Danny Colligan | last post by:
In the following code snippet, I attempt to assign 10 to every index in the list a and fail because when I try to assign number to 10, number is a deep copy of the ith index (is this statement...
0
by: sguitardude | last post by:
I am trying to log exceptions. It seems like I have to write the code for each member that I would like to log. It would be nice to replace this with code to enumerate an exception, but it seems...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.