[Bioperl-l] Bio::Root::RootI->throw($msg,$class) overloading?

Rutger Vos rvosa at sfu.ca
Tue Jul 11 08:58:46 UTC 2006


Dear all,

would it be possible to overload Bio::Root::RootI's 'throw' method to 
accept an additional, optional (positional) argument to define the 
exception class, e.g. using Exception::Class:

# ...somewhere ...

sub makefh {
    my ( $self, $filename ) = @_;
    open my $fh, '<' $filename or $self->throw("Can't open file: $!", 
'Bio::Exceptions::FileIO'); # NOTE second argument
    return $fh;
}

#.... somewhere else
my $fh;
eval {
    $fh = $obj->makefh( 'data.txt');
}
if ( $@ and $@->isa('Bio::Exceptions::FileIO') ) {
    # something's wrong with the file?
}

-- 
++++++++++++++++++++++++++++++++++++++++++++++++++++
Rutger Vos, PhD. candidate
Department of Biological Sciences
Simon Fraser University
8888 University Drive
Burnaby, BC, V5A1S6
Phone: 604-291-5625 
Fax: 604-291-3496
Personal site: http://www.sfu.ca/~rvosa
FAB* lab: http://www.sfu.ca/~fabstar
Bio::Phylo: http://search.cpan.org/~rvosa/Bio-Phylo/
++++++++++++++++++++++++++++++++++++++++++++++++++++





More information about the Bioperl-l mailing list