EasyExcel导入类型转换错误自定义异常

Before未定义异常情况

继承 AnalysisEventListener 重写 onException

@Override
    public void onException(Exception exception, AnalysisContext context) throws Exception {
        if (exception instanceof ExcelDataConvertException) {
            ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception;
            Integer row = excelDataConvertException.getRowIndex()+ 1;
            Integer column = excelDataConvertException.getColumnIndex()+1;
            throw new RuntimeException("第"+row+"行,第"+column+"列解析异常,请正确填写");
        }
    }

当抛出异常,停止读剩余数据,直接返回。

当没有抛出异常,忽略此行,继续读取插入

After

Before未定义异常情况 继承 AnalysisEventListener 重写 onException @Override public void onException(Exception exception, AnalysisContext context) throws Exception { if (exception instanceof ExcelDataConvertException) { ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception; Integer row = excelDataConvertException.getRowIndex()+ 1; Integer column = excelDataConvertException.getColumnIndex()+1; throw new RuntimeException("第"+row+"行,第"+column+"列解析异常,请正确填写"); } } 当抛出异常,停止读剩余数据,直接返回。 当没有抛出异常,忽略此行,继续读取插入 After
经验分享 程序员 微信小程序 职场和发展