0

首先,下面的代码已经运行了一段时间没有问题。我从一位同事那里收到了 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;
    }

我尝试调试,但我遇到了相同的行为,并且没有抛出异常,我不确定如何继续。

提前感谢您的反馈。

4

1 回答 1

0

捕获 Throwable 并查看而不是异常。它应该工作。

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

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

}
于 2012-12-06T07:14:15.177 回答