Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I've been having a problem with the

Status
Not open for further replies.

Raenius

Programmer
Oct 14, 2003
77
NL
I've been having a problem with the exception handling and catching, what is wrong with te following code? It is the load for a form in my app.

This is the code:

private void NewRouter_Load(object sender,System.EventArgs e)
{
try
{
string settings = "settings.xml";
XmlDocument xd = new XmlDocument();

if (settings != null)
{
// uitlezen van xml gegevens
xd.InnerXml = settings;
}
MessageBox.Show("succes!");
// this.textRouterIP.Text="hello";
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}


}

It gives back the errors:

[C# Error] NewRouter.cs(208): A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else
[C# Error] NewRouter.cs(210): 'System.EventArgs' does not contain a definition for 'Message'

Some help please!? ;-)

Thanks in advance...

- Raenius


"Free will...is an illusion"
 
Excuse me for not adding a descriptive title I was too eager to press the submit butten :(

- Raenius

"Free will...is an illusion"
 
catch(Exception e)
mut be
catch(Exception ex)
cause the variabl e is already declared:
private void NewRouter_Load(object sender,System.EventArgs e)


Stephan

 
ex.message will then display the exception message?

(thanks for the quick response!)

"Free will...is an illusion"
 
Yep, ex will then be your Exception object:

catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

BTW: You could call ex anything like myException .......
 
Allright thanks!!

Now I just want to know how i can access my XML document and put the data in there into variables....

Does anyone have a clue on that...?

(thanks!!!!!!)

- Raenius

"Free will...is an illusion"
 
Get the text from a node in xmlDocument:

string test = myDoc.DocumentElement.SelectSingleNode("//myNode").innerText.toString();

Get an Attribute
string attTest = myDoc.DocumentElement.SelectSingleNode("//myNode").Attributes.GetNamedItem("myAttribute").innerText.toString();

Did not test that, just to get on the right track.......

May I suggest buying a good C# Book?!? O'Reilly C# in a Nutshell ISBN: 3-89721-299-4
 
You may suggest it SgtPeppa, I'm already going to buy Programming C#, but thats for next week when I have time. For now I hope to continue on the way I am now...

I opened a topic for my XML question :)

Thanks for looking!

- Raenius

"Free will...is an illusion"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top