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

Steve Chervitz Steve_Chervitz at affymetrix.com
Wed Jul 12 00:21:16 UTC 2006


The Bio::Root::Root object is rigged to use the Error.pm module if
available, so you can throw and catch of exception objects derived from
Error. The motivation here was to provide a recommended path for folks that
want to use more structured exception handling logic in their bioperl code.

There are a number of pre-defined subclasses of exceptions that cover common
problems (such as FileOpenException), but you can also define your own. See
a list of the predfined exceptions as well as some how to docs in the POD
for Bio::Root::Exception:

http://search.cpan.org/~birney/bioperl-1.4/Bio/Root/Exception.pm

There's a bunch more info about Bioperl exception fun available from the
bioperl distribution under the examples/root directory. See the README in
that directory to get oriented. There are a number of demo scripts there,
too.

Bio::Root::Root doesn't know anything about Exception::Class, but I see you
can use it with Error.pm as described here:

http://search.cpan.org/~drolsky/Exception-Class-1.23/lib/Exception/Class.pm#
OTHER_EXCEPTION_MODULES_(try%2Fcatch_syntax)

Cheers,
Steve

> From: Hilmar Lapp <hlapp at gmx.net>
> Date: Tue, 11 Jul 2006 15:05:03 -0400
> To: Rutger Vos <rvosa at sfu.ca>
> Cc: Bioperl <bioperl-l at bioperl.org>, Steve Chervitz
> <steve_chervitz at affymetrix.com>
> Subject: Re: [Bioperl-l] Bio::Root::RootI->throw($msg,$class) overloading?
> 
> I think it does this already, except that I believe you need to
> create the exception object and initialize with the message upfront.
> 
> Steve, can you comment? Is this at least somewhat right?
> 
> -hilmar
> 
> On Jul 11, 2006, at 4:58 AM, Rutger Vos wrote:
> 
>> 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/
>> ++++++++++++++++++++++++++++++++++++++++++++++++++++
>> 
>> 
>> _______________________________________________
>> Bioperl-l mailing list
>> Bioperl-l at lists.open-bio.org
>> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>> 
> 
> -- 
> ===========================================================
> : Hilmar Lapp  -:-  Durham, NC  -:-  hlapp at gmx dot net :
> ===========================================================
> 
> 
> 
> 
> 




More information about the Bioperl-l mailing list