2012-12-06 36 views
0

首先,下面的代码已经运行一段时间没有问题了。 我从一位同事那里收到excel文件,我通过这个程序阅读和上传。 最近,同事被替换,我从另一个人收到文件。 我会和他一起检查他的excel文件。Apache POI退出而没有抛出异常

无论如何,我从新同事收到的第一个excel文件让我感到沮丧。 以下代码在WorkbookFactory.create(fis)调用中退出。没有异常抛出 和程序直接进到finally条款等

try { 
     fis = new FileInputStream(f);    

     Workbook wb = WorkbookFactory.create(fis); 

     Sheet ws = wb.getSheetAt(0); 
     if (ws == null) { 
      throw new ParseException("No sheet found on index 0", 1); 
     } 

     Iterator rowIt = ws.rowIterator(); 

     while (rowIt.hasNext()) { 
      Row row = (Row) rowIt.next(); 
      if (row.getRowNum() != 0 && isArticleRow(row)) { 
       Article article = parseArticleData(row); 

       if (article != null) { 
        priceList.getArticles().add(article); 
       } 
      } 
     } 

     String vendorNumber = getVendorNumber(priceList); 
     priceList.setVendorNumber(vendorNumber); 

     priceList.setReadCorrectly(true); 
     System.out.println("DONE"); 

    } catch (Exception e) { 
     System.out.println(e.getMessage()); 

     _log.error(e.getMessage()); 
     if (priceList != null) { 
      priceList.setReadCorrectly(false); 
     } 

    } finally { 
     if (fis != null) { 
      fis.close(); 
     } 
     return priceList; 
    } 

我试图调试,但我遇到相同的行为,并没有被抛出 例外,我不知道如何继续。

在此先感谢您的意见。

+0

什么使用调试器显示你正在发生? ;) –

+0

不是一个干净的解决方案,但尝试捕捉“Throwable”而不是异常,然后打印出来看看问题是什么......最有可能的运行时错误正在抛出...... – Pushkar

+0

是的,谢谢,这实际上是所有我需要。它似乎有些poi xml罐子丢失。由于以前的同事使用不同的excel格式,poi从不需要xml库。 – Treurwilg

回答

0

Catch Throwable,看看而不是例外。它应该工作。

} catch (Throwable e) { 
    System.out.println(e.getMessage()); 

    _log.error(e.getMessage()); 
    if (priceList != null) { 
     priceList.setReadCorrectly(false); 
    } 

} 
+0

是的,它的工作原理,我发现了异常,并抓到了一个classDefNotFound错误。看到我上面的评论,有些罐子丢失了。 非常感谢 – Treurwilg