Using System.Exception.Data ??

  • Thread starter Thread starter newscorrespondent
  • Start date Start date
N

newscorrespondent

A System.Exception has a Data property that I would like to add data to
before I call my standard exception handler. When in a routine that uses SQL
server I would like to add the
System.Data.SqlClient.SqlConnectionSQLConnection,
System.Data.SqlClient.SqlCommand and System.Data.SqlClient.SqlDataReader
when there is one.

Exception abc = new Exception("abc");
abc.Data.Add("TheConnection",TheConnection);
abc.Data.Add("TheSQLCommand", TheSQLCommand);
abc.Data.Add("Reader", TheReader);

This compiles but at run time an exception is thrown because these are not
serialiazable. How can I put these into the Excpetions data property?

Thanks
 
You probably need to write your own Serlialiable class.

You will have 3 constructors.
Here is one of them.

public class MyClass
{
private SqlReader m_sr = null;
MyClass( SqlReader sr )
{
this.m_sr = sr;
}
}

You can try that and expose a property for m_sr.

However, you may have to parse m_sr and provide member variarbles/properties
for the items of m_sr you want to deal with.

Then you try this:

abc.Data.Add("MyClassKey" , new MyClass ( TheReader ));


I think thats a good way to try it. But its just an idea.
 
When I add a class attribute of:

[SerializableAttribute]

it works.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top