[英]Apache POI exits without throwing exception
首先,下面的代碼已經有一段時間沒有出現問題了。 我從同事那里收到了excel文件,並使用該程序進行了讀取和上傳。 最近同事被替換了,我收到了另一個人的文件。 我也會和他一起檢查他對excel文件的處理方式。
無論如何,我從新同事那里收到的第一個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;
}
我嘗試調試,但是我遇到了相同的行為,並且毫無疑問地拋出異常,我不確定如何繼續。
預先感謝您的反饋。
捕獲Throwable並查看而不是Exception。 它應該工作。
} catch (Throwable e) {
System.out.println(e.getMessage());
_log.error(e.getMessage());
if (priceList != null) {
priceList.setReadCorrectly(false);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.