XmlException message disappears.

  • Thread starter Thread starter BLUE
  • Start date Start date
B

BLUE

In a property i do this:
....
catch(XmlException e)
{
throw new XmlException("Error processing configuration file!",e);
}

Then I catch it in another class:
catch(XmlException e)
{
MessageBox.Show(e.Message + e.InnerException.Message);
}

With the debugger I see that "Error processing configuration file!" is not
in Message property but in a private field called "args".
Why?
How can I obtain "Error processing configuration file!" being in e.Message
or how can I retrieve args content?
 
Blue,

I'm not sure why this is happening to you; however, this:

using System.Xml;

class Program
{
static void Main(string[] args)
{
Class1 c1 = new Class1();
c1.DoIt();

Console.WriteLine("Hit enter to exit");
Console.ReadLine();
}
}

public class Class1
{
public void DoIt()
{
try
{
Class2 c2 = new Class2();
c2.OneProperty = 0;
}
catch (XmlException e)
{
Console.WriteLine(e.Message + e.InnerException.Message);
}
}
}

public class Class2
{
private int _oneValue = 0;

public int OneProperty
{
get { return _oneValue; }
set
{
try
{
if (value > 1)
_oneValue = 1;
else throw new XmlException("Original message");
}
catch(XmlException e)
{
throw new XmlException("Error processing configuration file!",
e);
}
}
}
}

produces the text:
Error processing configuration file!Original message


Dave
 

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