SPUG: can't die() from XML::Parser handlers?

Jason Lamport jason at strangelight.com
Fri Sep 14 23:48:53 CDT 2001

I've discovered what I consider very strange behaviour in XML::Parser:

I'm using the 'Subs' style of parsing, like this:

use XML::Parser;

# ....

	my $parser = new XML::Parser(
		Style => 'Subs',
		Pkg => 'my_Handlers',
	$parser->parsefile( $SOME_XML_FILE );

package my_Handlers;

sub table {
	my $table_id;

	# ... some stuff to find the "id" attribute

	die( "table must have an id attribute" ) unless defined $table_id;

	# ... more stuff


Now, it turned out that due to an error in the XML file, $table_id 
was in fact undef inside table().  The weird thing is that the die() 
call isn't causing the program to die:  it just exits the handler but 
keeps on going parsing the XML file as if nothing had happened.  I 
can only assume that XML::Parser is calling the handlers from inside 
an eval block (which would make sense) and then ignoring the error 
messages (which doesn't make any sense at all).

I don't get it.  Is this a bug or some sort of feature that I'm 
understanding?  How can I get the handlers to raise a fatal 
exception? (Of course I can think of  plenty of kludgey work-arounds, 
but nothing elegant.)


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/

More information about the spug-list mailing list