For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > June 2005 > XML::Twig exception handling









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author XML::Twig exception handling
Peter Rabbitson

2005-06-03, 8:58 am

Hello,

I am interfacing an XML file with a database, much like the last example at
http://www.xmltwig.com/xmltwig/tuto...pc_twig_s5.html
What I am actually doing is checking if the table already got such a record,
if so - updating it, otherwise inserting it, but this is not relevant.

Either way I can't figure out how to raise an exception in the insert_row
subroutine so that the parsefile() will die as well. Since I am working with
records totalling several gigabytes, I am checking every SQL operation by
evaling them with RaiseError turned on. This doesn't help me much, however,
since the best I can do after a failure is return from the subroutine and
XML::Twig will continue with its business. I could issue a finish() and the
parser should (?) stop processing the XML, but it will still return with a
success (I am performing safe_parsefile), and it actually doesn't seem to
stop at all, chewing through the rest of the file. If this is true (finish()
works as I think it works) then I guess I could use a global flag that will
be raised if one of the inserts fails. Then after the parsefile() I will
check it and rollback all changes to the db, but this seems really retarded.
Are there some better ways to do this that I am overlooking?

Thanks

Peter
Peter Rabbitson

2005-06-03, 3:56 pm

> Either way I can't figure out how to raise an exception in the insert_row
> subroutine so that the parsefile() will die as well. Since I am working with
> records totalling several gigabytes, I am checking every SQL operation by
> evaling them with RaiseError turned on. This doesn't help me much, however,
> since the best I can do after a failure is return from the subroutine and
> XML::Twig will continue with its business. I could issue a finish() and the
> parser should (?) stop processing the XML, but it will still return with a
> success (I am performing safe_parsefile), and it actually doesn't seem to
> stop at all, chewing through the rest of the file. If this is true (finish()
> works as I think it works) then I guess I could use a global flag that will
> be raised if one of the inserts fails. Then after the parsefile() I will
> check it and rollback all changes to the db, but this seems really retarded.
> Are there some better ways to do this that I am overlooking?
>


Some days I am dumber than other days. If I die() inside the handler
subroutine, parsefile dies as well, and is caught be the global eval created
by safe_parsefile.
Excuse the noise :)

Peter
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com