0

I'm creating XML parser using C#. I need to display all exceptions on the windows form that I am using. However, I can only get one exception at a time.

for example, I'm parsing: test.xml

<xml>
<head>
<title>Book</title>
<head>
<xml>

If you notice there are 2 unclosed tags for head and xml tags. This is part of the c# code:

        catch (XmlException f)
            {
                MessageBox.Show(f.Message);                   
            }

If I run the program, it will only throw an exception to tell that head tag is unclosed.
However, if I just corrected the unclosed tag for head(i.e. /head), then the exception will now only throw regarding xml tag. Is there a way to scan the whole xml file without throwing errors first, at the end of the scan, throw both exceptions to user at the same time?

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Oxiegen
0

An exception, of any type, is always thrown on the first encountered error.

Here's my take on it:
If you want to throw one single exception for all occuring errors, then you need to read the entire file into a string variable with a TextReader, and create a parser that scans the string for all possible reasons an error could occur.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.