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

Rutger Vos rvosa at sfu.ca
Tue Jul 11 18:58:25 UTC 2006


I must have overlooked this. I think it does what I want. So could I do 
something like:

$obj->thow_not_implemented( -class => 'Bio::Root::NotImplemented' );

...in interfaces?

Chris Fields wrote:
> I suppose you could; Bio::Root::Root does that using Error.pm (if it  
> is installed).  It almost sounds like what Bio::Root::Root does is  
> what you want, but you want a little more information when exceptions  
> are thrown maybe?
>
> from perldoc Bio::Root::Root:
>
> ...
>           # Alternatively, using the new typed exception syntax in  
> the throw() call:
>
>             $obj->throw( -class => 'Bio::Root::BadParameter',
>                          -text  => "Can not open file $file",
>                          -value  => $file);
> ...
>
>         Typed Exception Syntax
>
>         The typed exception syntax of throw() has the advantage of  
> plainly
>         indicating the nature of the trouble, since the name of the  
> class is
>         included in the title of the exception output.
>
>         To take advantage of this capability, you must specify  
> arguments as
>         named parameters in the throw() call. Here are the parameters:
>
>         -class
>             name of the class of the exception.  This should be one  
> of the
>             classes defined in Bio::Root::Exception, or a custom  
> error of yours
>             that extends one of the exceptions defined in  
> Bio::Root::Exception.
>
>         -text
>             a sensible message for the exception
>
>         -value
>             the value causing the exception or $!, if appropriate.
>
>         Note that Bio::Root::Exception does not need to be imported  
> into your
>         module (or script) namespace in order to throw exceptions via
>         Bio::Root::Root::throw(), since Bio::Root::Root imports it.
>
>
> Chris
>
> On Jul 11, 2006, at 3: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
>>     
>
> Christopher Fields
> Postdoctoral Researcher
> Lab of Dr. Robert Switzer
> Dept of Biochemistry
> University of Illinois Urbana-Champaign
>
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>
>
>
>   

-- 
++++++++++++++++++++++++++++++++++++++++++++++++++++
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