[Bioperl-l] Grrrr. Another subtle overloading bug ...

Ewan Birney birney@ebi.ac.uk
Sun, 6 Jan 2002 18:38:59 +0000 (GMT)


SteveC - you are going to get awards for introducing the most bizarre bugs
across bioperl namespaces if we are not careful....


The new Exception class SteveC checked in (at my behest to get things
checked in early) now throws objects not scalars...


These objects have a stringify method which evaluates to the expected
string when printed - quite right


... but there is a *VERY* nasty side-effect ....


which is that scenarios like


  eval {
	# do complex stuff
	# which might throw an exception
  };

  if( $@ ) { # you would expect this to evaluate to "true" on exception
    # do something else, like return failure gracefully
  } else {
    # do something sanely
  }


This construct WONT work. <sigh>

The reason is that 

  if( $@ ) triggers the "stringify" method, which gives back a nice piece
of text and then gets evaluated as a number (I think...), which goes to 0
which evaluates as .... FALSE.


  ...Grrrrr...


I suspect world wide we have lots of

  if( $@ ) {

  }


(certainly there is alot in Ensembl...)


Now ... I have commited some tests to fix this but then I realised that
this is probably a bad idea and we need to fix things so that


  if( $@ ) {
   #
  }

Evaluates to TRUE. SteveC - do you know how to do this. I have spent a
fruitless half an hour in perl.com trying to find the overloading
documentation.



This is a nasty bug and something we have to get right. It also emphasises
how important it is to test the 0.9 series before we call it 1.0 otherwise
we will just trigger alot of bugs world-wide...



ewan