[Biojava-dev] Errors versus Exceptions

Andy Yates ayates at ebi.ac.uk
Mon May 17 14:26:25 UTC 2010


Hi Andreas,

That is a fair point and Effective Java is the Perl Best Practices for Java. ERH (opinionated but right more often than not) also gives some good advice on this:

http://cafe.elharo.com/programming/bruce-eckel-is-wrong

If everyone is okay with checked exceptions then that's fine. We'll have to tighten up the parts of the API which currently throw these and make sure that we do not pass back Exception but the right types of Exceptions where applicable.

Andy

On 17 May 2010, at 15:11, Andreas Prlic wrote:

> Hi Andy,
> 
> On this topic I am with Josha Bloch (Effective Java) :  His point is
> that checked exceptions should be  used for recoverable errors and
> runtime exceptions for programming errors.
> 
> Passing in a wrong sequence is a recoverable errors (the software
> should ask the user to select a different sequence). As such this
> would suggest the use of checked exceptions.
> 
> Andreas
> 
> 
> 
> On Mon, May 17, 2010 at 6:49 AM, Andy Yates <ayates at ebi.ac.uk> wrote:
>> I think this opens us up to one of the initial points about BioJava3 was to make it easier for the entry level programmer as well as to the more experienced programmer. Much like having one's cake & eating it too :). Assuming the following signature:
>> 
>> setContents() throws UnknownCompoundException;
>> 
>> What would give us the best API. Where
>> 
>> 1). UnknownCompoundException extends Exception
>> 
>> This has the knock on effect of turning our Sequence constructors into:
>> 
>> DNASequence s;
>> try {
>>  s = new DNASequence("ATGC");
>> }
>> catch(UnknownCompoundException e) {
>>  //....
>> }
>> 
>> There is of course the option of swallowing/reporting exceptions under certain circumstances (say this constructor) but that results in inconsistent API behaviour.
>> 
>> 2). UnknownCompoundException extends RuntimeException
>> 
>> Has the problem that should anything *need* to deal with the exception it doesn't have to.
>> 
>> 
>> I don't know what the right answer is here so I'm happy to be led by whoever feels the strongest about it
>> 
>> Andy
>> 
>> On 17 May 2010, at 14:37, Scooter Willis wrote:
>> 
>>> Andy
>>> 
>>> I think it is reasonable in the creation of sequences to have invalid chars passed in where we have probably covered the obvious cases - . etc. We recently came across N for DNA and X for aligned output from Blast. I know in our lab they started using different chars for PTM's so it will be tough to predict all cases. The developer would have two options at this point based on the error/exception they change the sequence data to a correct format or do their own custom compound mapping. Since that is more of a user input error and outside our control we should probably throw the appropriate exception and let the user deal with it.
>>> 
>>> Scooter
>>> 
>>> 
>>> 
>>> On May 17, 2010, at 9:24 AM, Andy Yates wrote:
>>> 
>>>> Is the problem in the code the fact that errors are used or that they are not declared on the method signatures?
>>>> 
>>>> On a more design note I do not like checked exceptions for two reasons. The first is they seem to make more junior developers catch Exception and swallow it. The second is whenever I've been Java coding in the past whenever a checked exception gets thrown (say IOException because of incorrect file permissions) I cannot deal with it which in the past has meant I either forward on the problem or re-throw in an unchecked exception.
>>>> 
>>>> That said as Scooter mentioned the exception system was rushed out in the hackathon and did not have much work put into it.
>>>> 
>>>> Andy
>>>> 
>>>> On 17 May 2010, at 13:15, PATERSON Trevor wrote:
>>>> 
>>>>> resending cos of bad headers
>>>>> 
>>>>> ________________________________
>>>>> 
>>>>> From: PATERSON Trevor
>>>>> Sent: 17 May 2010 13:02
>>>>> To: biojava-dev at lists.open-bio.org
>>>>> Subject: Errors versus Exceptions
>>>>> 
>>>>> 
>>>>> Could I ask a quick question about why BJ3 seems to use Errors rather than Exceptions
>>>>> - maybe this is already documented somewhere on the wiki for BJ3 or 1 - and you can point me there.
>>>>> 
>>>>> Obviously for us dataloading from remote databases we need to have a method to catch connection,sql, datamapping errors etc.
>>>>> We ususally throw DataAccessExceptions when this happens, which wrap any java.net, Ibatis and SQL exceptions.
>>>>> 
>>>>> It is difficult for us to plug in our lazyload over your signatures in the BJ3 sequence readers, as these don't throw exceptions,
>>>>> because you seem to use Errors throughout - which dont need to be declared. Infact I cant actually see examples of you catching
>>>>> and responding to thrown errors.
>>>>> 
>>>>> for example the setContents routine of the Sequence Readers throws a  CompoundNotFoundError if there is no mapping for a base -
>>>>> but I can't see what is done with this.
>>>>> 
>>>>> According to the Java Lang Spec, errors are used for "serious problems that a reasonable application
>>>>> should not try to catch" - but I would have thought finding an unrecognized base in a sequence was
>>>>> just the sort of thing that should be thrown and caught and acted on. As error throwables are not reported
>>>>> in the signature - developers don't have any clue ( or requirement) that they should be catching and dealing with errors - which
>>>>> seems a bit dangerous to me... If Exceptions were thrownrather than Errors that would force the developer to handle runtime errors
>>>>> 
>>>>> Cheers Trevor
>>>>> 
>>>>> --
>>>>> The University of Edinburgh is a charitable body, registered in
>>>>> Scotland, with registration number SC005336.
>>>>> 
>>>>> 
>>>>> _______________________________________________
>>>>> biojava-dev mailing list
>>>>> biojava-dev at lists.open-bio.org
>>>>> http://lists.open-bio.org/mailman/listinfo/biojava-dev
>>>> 
>>>> --
>>>> Andrew Yates                   Ensembl Genomes Engineer
>>>> EMBL-EBI                       Tel: +44-(0)1223-492538
>>>> Wellcome Trust Genome Campus   Fax: +44-(0)1223-494468
>>>> Cambridge CB10 1SD, UK         http://www.ensemblgenomes.org/
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> _______________________________________________
>>>> biojava-dev mailing list
>>>> biojava-dev at lists.open-bio.org
>>>> http://lists.open-bio.org/mailman/listinfo/biojava-dev
>>> 
>> 
>> --
>> Andrew Yates                   Ensembl Genomes Engineer
>> EMBL-EBI                       Tel: +44-(0)1223-492538
>> Wellcome Trust Genome Campus   Fax: +44-(0)1223-494468
>> Cambridge CB10 1SD, UK         http://www.ensemblgenomes.org/
>> 
>> 
>> 
>> 
>> 
>> _______________________________________________
>> biojava-dev mailing list
>> biojava-dev at lists.open-bio.org
>> http://lists.open-bio.org/mailman/listinfo/biojava-dev
>> 
> 
> 
> 
> -- 
> -----------------------------------------------------------------------
> Dr. Andreas Prlic
> Senior Scientist, RCSB PDB Protein Data Bank
> University of California, San Diego
> (+1) 858.246.0526
> -----------------------------------------------------------------------

-- 
Andrew Yates                   Ensembl Genomes Engineer
EMBL-EBI                       Tel: +44-(0)1223-492538
Wellcome Trust Genome Campus   Fax: +44-(0)1223-494468
Cambridge CB10 1SD, UK         http://www.ensemblgenomes.org/








More information about the biojava-dev mailing list