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(CharacterTok > 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@biojava.org > http://biojava.org/mailman/listinfo/biojava-l > _______________________________________________ Biojava-l mailing list - Biojava-l@biojava.org http://biojava.org/mailman/listinfo/biojava-l