[Biojava-l] Exception not being caught.

mark.schreiber at group.novartis.com mark.schreiber at group.novartis.com
Thu Jan 6 21:43:13 EST 2005


I tend to agree. This probably shouldn't be an error. It should be 
possible to recover from it. Having said that changing it might be a bit 
of a headache. You don't need to catch Errors but if we make it an 
Exception then old code will be invalid because you do need to catch 
exceptions.

A possible way around would be to make a RuntimeException which you don't 
need to catch but then you are pretty much back to the situation of 
catching a Throwable so there is no real advantage. Also, 
RuntimeExceptions are pretty much reserved for things that happen due to 
bad programming such as NullPointerExceptions.

As a general rule BioJava shouldn't use Errors unless something truely bad 
happens, such as not being able to locate a critical resource like 
AlphabetManager.xml. That sort of thing would be very hard to recover from 
and should be an error. Someone passing some crap sequence to a parser 
shouldn't be an error.

- Mark





"Richard HOLLAND" <hollandr at gis.a-star.edu.sg>
Sent by: biojava-l-bounces at portal.open-bio.org
12/29/2004 01:14 PM

 
        To:     "Michael Heuer" <heuermh at acm.org>
        cc:     biojava-l at biojava.org, (bcc: Mark Schreiber/GP/Novartis)
        Subject:        RE: [Biojava-l] Exception not being caught.


Hi,

I resolved the exception by adding a trim() call to truncate whitespace
from the ends of the sequence before passing it to DNATools. There were
some weird trailing blank symbols, \0, \r, \n and the like. Fair enough
that it threw a wobbly when it encountered these. However, I am sure
there are situations where you would want to safely know whether a
sequence contained invalid characters (eg. if accepting free-text
sequence information via a web interface). In this case, you would want
to catch the exception in the usual manner.

Should this particular BioError not be a plain normal BioException that
people could catch easily?

cheers,
Richard

Richard Holland
Bioinformatics Specialist
GIS extension 8199 
 
---------------------------------------------
This email is confidential and may be privileged. If you are not the
intended recipient, please delete it and notify us immediately. Please
do not copy or use it for any purpose, or disclose its content to any
other person. Thank you.
---------------------------------------------


> -----Original Message-----
> From: Michael Heuer [mailto:heuermh at shell3.shore.net] On 
> Behalf Of Michael Heuer
> Sent: Wednesday, December 29, 2004 12:25 PM
> To: Richard HOLLAND
> Cc: biojava-l at biojava.org
> Subject: Re: [Biojava-l] Exception not being caught.
> 
> 
> 
> On Wed, 29 Dec 2004, Richard HOLLAND wrote:
> 
> > I am getting an exception thrown by my code that never seems to get
> > caught. I am not sure if this is because of BioJava or 
> because of a lack
> > of understanding of Exceptions on my part? The exception causes the
> > program to grind to an immediate halt. My method throws the general
> > Exception class, but the exception thrown by BioJava seems to escape
> > that detail and treats it as though my method were not handling
> > exceptions at all. I would expect the calling method which wraps the
> > call in a try{}catch{Exception e} statement to catch it? 
> But apparently
> > not? Why not?!!
> >
> > The method in BioJava I am using is DNATools.createDNASequence.
> >
> > Here is the exception:
> >
> > Exception in thread "main" org.biojava.bio.BioError: 
> Something has gone
> > badly wrong with DNA
> >         at org.biojava.bio.seq.DNATools.createDNA(DNATools.java:158)
> 
> Unfortunately BioError is not an exception, it is an Error.
> 
> I believe you can catch them with
> 
> try
> {
>   // ...
> }
> catch (Throwable t)
> {
>   // ...
> }
> 
> but you probably shouldn't be.  From the BioError javadoc:
> 
> For developers:
> Throw this when something has gone wrong and in general people should
> not be handling it.
> 
> 
> 
> > org.biojava.bio.seq.DNATools.createDNASequence(DNATools.java:176)
> >         at
> > 
> gis.aads.pipeline.LibraryFastaBuilder.run(LibraryFastaBuilder.
> java:234)
> >         at gis.pipeline.Main.main(Main.java:125)
> > Caused by: org.biojava.bio.symbol.IllegalSymbolException: This
> > tokenization doesn't contain character: ''
> >         at
> > 
> org.biojava.bio.seq.io.CharacterTokenization.parseTokenChar(Ch
> aracterTok
> > enization.java:175)
> 
> This is the real problem:  the parser doesn't know what to do with the
> character ''.  I don't know exactly what that means, but does 
> the string
> you pull out of the database clob look reasonable?
> 
>    michael
> 
> 
> > And here is the method that calls it (or bits of it anyhow, and an
> > example calling method):
> >
> >     public void doTheThing() {
> >               MyClass otherClass = new MyClass();
> >        try {
> >                  int rc = otherClass.run();
> >                  System.out.println("rc was "+rc);
> >        } catch (Exception e) {
> >           System.out.println("oops!");
> >        }
> >     }
> >
> >     public int run() throws Exception {
> > ....
> >         // For each library, get all trimmed seqs.
> >         for (String lib : libs) {
> >             log.info("Processing library "+lib);
> > ....
> >             // Get the sequences.
> >             seqq.execute(lib);
> >             rs = seqq.results();
> >
> >             // Log info.
> >             log.info("Processing fasta.");
> >             while (rs.next()) {
> >                 // Get details.
> >                 String seqID = rs.getString(1);
> >                 char direction = UserSampleID.getDirection(seqID);
> >                 Clob seqclob = rs.getClob(2);
> >                 String seqstr =
> > seqclob.getSubString((long)1,(int)seqclob.length());
> >                 if (seqstr.length()<minLength) continue;
> >
> >                 // Create the sequence and format it into fasta.
> >                 Sequence seq = DNATools.createDNASequence(seqstr,
> > seqID);
> >                 ByteArrayOutputStream baos = new
> > ByteArrayOutputStream();
> >                 SeqIOTools.writeFasta(baos,seq);
> >                 baos.flush();
> >
> >                 // For each seq, if reverse, add to reverse 
> temp file.
> >                 // Else, add to forward temp file.
> >                 switch (direction) {
> >                     case 'R':
> >                         reverseWriter.write(baos.toString());
> >                         break;
> >                     case 'F':
> >                         forwardWriter.write(baos.toString());
> >                         break;
> >                     default:
> >                         log.warning("Unknown direction "+direction+"
> > received for sequence "+seqID);
> >                         rc = PipelineApp.FAILURE;
> >                         continue;
> >                 }
> > ....
> >             }
> > ....
> >         }
> > ....
> >     }
> >
> >
> > I understand that the exception is thrown because of an invalid
> > sequence, but I don't understand why it isn't being caught.
> >
> >
> > Richard Holland
> > Bioinformatics Specialist
> > GIS extension 8199
> >
> > ---------------------------------------------
> > This email is confidential and may be privileged. If you are not the
> > intended recipient, please delete it and notify us 
> immediately. Please
> > do not copy or use it for any purpose, or disclose its 
> content to any
> > other person. Thank you.
> > ---------------------------------------------
> >
> >
> > _______________________________________________
> > Biojava-l mailing list  -  Biojava-l at biojava.org
> > http://biojava.org/mailman/listinfo/biojava-l
> >
> 
> 

_______________________________________________
Biojava-l mailing list  -  Biojava-l at biojava.org
http://biojava.org/mailman/listinfo/biojava-l





More information about the Biojava-l mailing list