Re: Shortcutting a SAX parser

"Jenda Krynicky" <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
From:           	Michael Ludwig <[email protected]>
> Robin Berjon schrieb:
>    http://perl-xml.sourceforge.net/perl-sax/sax-2.1.html#Exceptions
>    perldoc XML::SAX::Exception
> 
> > If you want to be absolutely strict and defensive in your programming,
> > you probably want to throw a specific exception (SAX exceptions are
> > expected to have at least a Message key with a reason for throwing)
> > and check that that's the one you're getting. That way, if your
> > document does turn out to have a problem, your code won't confuse
> > "threw because I got what I wanted" with "threw because something
> > smells bad".
> 
> That's true, of course you really should do that. However, two things
> combine to make this difficult.
> 
> First, after a die(), the $@ variable also contains (from the point of
> view of the program logic) random line number information, which, in a
> hackerish manner, you'd then have to weed out in order to compare the
> string to the expected one.
> 
>    eval { die 'Gurke' };
>    print $@ if $@;

Compare

    eval { die "Gurke\n" };
    print $@ if $@;


> Second, the documentation I referred to above does not describe the
> behaviour I'm observing. $@ is not a blessed hash reference, but a
> simple string. Maybe that has to do with the fact that the class
> overloads "", but then, I don't know how to get at the object.

  use XML::SAX::Exception;
  @XML::SAX::Exception::Done::ISA = ('XML::SAX::Exception');

  use Data::Dumper; 
  eval { throw XML::SAX::Exception::Done( Message => 'Doc done' ); };
  print Dumper($@) if $@;

seems to work for me. If it doesn't for you, someone must be catching 
and rethrowing the exception and stringifying it along the way.

Jenda
===== [email protected] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
	-- Terry Pratchett in Sourcery

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.