473,394 Members | 1,854 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,394 software developers and data experts.

Catching Exception


I am updating my apps to use XML files rather than ini files for
application settings.

As a first step I am writing an XML editor (rather like an ini editor)
so I can learn how this works. I have the following line:

try
{
txtXMLName.Text = xmlRead.Name;

The problem is that in reading an XML file that doesn't have a'Name'
the app raises an exception and stops, even though it is in a 'try'
block.

Is there any way of testing for this and retreating gracefully?

Apologies if I have the terminology wrong, this is all new to me! The
following is an XML file:

<?xml version="1.0" encoding="Windows-1252"?>
<!-- JG Config File -->
<!-- Modify at Your Peril :-) -->
<Map JDATADIR="E:\Data\DataBase" JINFODIR="E:\Data\JHelp" />

and if the entry 'Map' is missing I get the error outlined above. I am
treating this like a section heading in an ini file but that may be
the wrong approach.

Many thanks.
--
Jeff Gaines Damerham Hampshire UK

Nov 11 '05 #1
2 1283
Jeff Gaines wrote:
As a first step I am writing an XML editor (rather like an ini editor)
so I can learn how this works. I have the following line:

try
{
txtXMLName.Text = xmlRead.Name;

The problem is that in reading an XML file that doesn't have a'Name'
the app raises an exception and stops, even though it is in a 'try'
block.
If xmlRea? is XmlReader, then Name property of course always exists.
Hmm, this is too bizarre, show us more code - what is xmlRead?
<?xml version="1.0" encoding="Windows-1252"?>
<!-- JG Config File -->
<!-- Modify at Your Peril :-) -->
<Map JDATADIR="E:\Data\DataBase" JINFODIR="E:\Data\JHelp" />

and if the entry 'Map' is missing I get the error outlined above.

Any XML document must have single root element. If Map element is
missing, such XML is not wellformed and cannot be processed.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
On Sat, 20 Sep 2003 20:45:21 +0300, Oleg Tkachenko
<oleg@NO_SPAM_PLEASEtkachenko.com> wrote:
Jeff Gaines wrote:
As a first step I am writing an XML editor (rather like an ini editor)
so I can learn how this works. I have the following line:

try
{
txtXMLName.Text = xmlRead.Name;

The problem is that in reading an XML file that doesn't have a'Name'
the app raises an exception and stops, even though it is in a 'try'
block.


If xmlRea? is XmlReader, then Name property of course always exists.
Hmm, this is too bizarre, show us more code - what is xmlRead?
<?xml version="1.0" encoding="Windows-1252"?>
<!-- JG Config File -->
<!-- Modify at Your Peril :-) -->
<Map JDATADIR="E:\Data\DataBase" JINFODIR="E:\Data\JHelp" />

and if the entry 'Map' is missing I get the error outlined above.

Any XML document must have single root element. If Map element is
missing, such XML is not wellformed and cannot be processed.


Hi Oleg, thanks for your reply.

I have now discovered the error arises just before I enter the 'try'
block so all is actually working as expected - i.e. not working :-))

I was hoping to treat an XML file like an ini file and just pull a
value out from a key name but it seems slightly more tricky than that
although I think I am making progress.

Thanks again for your reply.
--
Jeff Gaines Damerham Hampshire UK

Nov 11 '05 #3

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

Similar topics

8
by: Adam H. Peterson | last post by:
Hello, I sometimes find myself writing code something like this: try { Derived &d=dynamic_cast<Derived&>(b); d.do_something_complicated(); // etc.... } catch (std::bad_cast) { throw...
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
2
by: Geoff O | last post by:
I have a try catch block in a web service that executes ADO.NET code that interfaces with an Oracle database. In addition, I have a try catch block in the client around the call to the web...
3
by: john | last post by:
I wrapped some fortran code using F2PY and need to be able to catch fortran runtime errors to run the following: # "grid" is a wrapped fortran module # no runtime errors incurred when run with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.