Changeset 1882


Ignore:
Timestamp:
11/30/06 09:33:53 (13 years ago)
Author:
curtis
Message:

Cleaner exception handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/OmeisImporter.java

    r1831 r1882  
    127127   * dumped to standard output. 
    128128   */ 
    129   public void importIds(int[] fileIds) throws OmeisException { 
     129  public void importIds(int[] fileIds) 
     130    throws OmeisException, FormatException, IOException 
     131  { 
    130132    boolean doLittle = isLittleEndian(); 
    131133 
     
    143145    String path = reader.getMappedId(ids[0]); 
    144146    if (DEBUG) log("Reading file '" + id + "' --> " + path); 
    145     try { 
     147 
    146148      // verify that all given file IDs were grouped by the file stitcher 
    147149      FilePattern fp = reader.getFilePattern(id); 
    148150      if (!fp.isValid()) { 
    149         log("Error: invalid file pattern for " + path); 
    150         if (http) printHttpErrorHeader(); 
    151         return; 
     151        throw new FormatException("Invalid file pattern for " + path); 
    152152      } 
    153153      String[] files = fp.getFiles(); 
    154154      if (files == null) { 
    155         log("Error: invalid file list for " + path); 
    156         if (http) printHttpErrorHeader(); 
    157         return; 
     155        throw new FormatException("Invalid file list for " + path); 
    158156      } 
    159157      if (files.length != ids.length) { 
    160         log("Error: file list length mismatch for " + path); 
    161         if (http) printHttpErrorHeader(); 
    162         return; 
     158        throw new FormatException("File list length mismatch for " + path); 
    163159      } 
    164160      boolean[] done = new boolean[ids.length]; 
     
    175171      } 
    176172      if (numLeft > 0) { 
    177         log("Error: file list does not correspond to ID list for " + path); 
    178         if (http) printHttpErrorHeader(); 
    179         return; 
     173        throw new FormatException( 
     174          "File list does not correspond to ID list for " + path); 
    180175      } 
    181176 
     
    184179      // get DOM and Pixels elements for the file's OME-XML metadata 
    185180      OMENode ome = (OMENode) store.getRoot(); 
    186       Document omeDoc = ome.getOMEDocument(false); 
     181      Document omeDoc = null; 
     182      try { 
     183        omeDoc = ome.getOMEDocument(false); 
     184      } 
     185      catch (javax.xml.transform.TransformerException exc) { 
     186        throw new FormatException(exc); 
     187      } 
     188      catch (org.xml.sax.SAXException exc) { 
     189        throw new FormatException(exc); 
     190      } 
     191      catch (javax.xml.parsers.ParserConfigurationException exc) { 
     192        throw new FormatException(exc); 
     193      } 
    187194      Vector pix = DOMUtil.findElementList("Pixels", omeDoc); 
    188195      if (pix.size() != seriesCount) { 
    189         log("Error: Pixels element count (" + 
     196        throw new FormatException("Pixels element count (" + 
    190197          pix.size() + ") does not match series count (" + 
    191198          seriesCount + ") for '" + id + "'"); 
    192         if (http) printHttpErrorHeader(); 
    193         return; 
    194199      } 
    195200      if (DEBUG) log(seriesCount + " series detected."); 
     
    249254            break; 
    250255          default: 
    251             log("Error: unknown pixel type for '" + 
     256            throw new FormatException("Unknown pixel type for '" + 
    252257              id + "' series #" + s + ": " + pixelType); 
    253             if (http) printHttpErrorHeader(); 
    254             return; 
    255258        } 
    256259        boolean little = reader.isLittleEndian(id); 
     
    310313      // accumulate XML into buffer 
    311314      ByteArrayOutputStream xml = new ByteArrayOutputStream(); 
    312       DOMUtil.writeXML(xml, omeDoc); 
     315      try { 
     316        DOMUtil.writeXML(xml, omeDoc); 
     317      } 
     318      catch (javax.xml.transform.TransformerException exc) { 
     319        throw new FormatException(exc); 
     320      } 
    313321 
    314322      // output OME-XML to standard output 
     
    318326      if (http) printHttpResponseHeader(); 
    319327      System.out.println(xmlString); 
    320     } 
    321     catch (Exception exc) { 
    322       log("Error: an exception occurred importing " + path + ":"); 
    323       exc.printStackTrace(); 
    324       if (http) printHttpErrorHeader(); 
    325     } 
    326328  } 
    327329 
Note: See TracChangeset for help on using the changeset viewer.