问题描述
我在一个使用 java 6 的系统中工作。 我已经实现了一个读取 xml 文件、解析它并将数据保存在 DB 中的组件。 实现如下所示。
void importXMLFiles() throws ImportFailedException
{
LOGGER.info("Started importing XML files.");
try
{
xmlImportHandler.importData(getXMLData());
LOGGER.info("Successfully imported XML files.");
}
catch (ImportHandlerNotFoundException e)
{
LOGGER.error("Importing XML files Failed Due to an unexpected error.");
throw new ImportFailedException(e.getMessage(),e);
}
catch (XMLFileCannotBeReadException e)
{
LOGGER.error("Importing XML files Failed Due to an unexpected error.");
throw new ImportFailedException(e.getMessage(),e);
}
catch (XMLFileNotFoundException e)
{
LOGGER.error("Importing XML files Failed Due to an unexpected error.");
throw new ImportFailedException(e.getMessage(),e);
}
catch (XMLConfigurationsMissingException e)
{
LOGGER.error("Importing XML files Failed Due to an unexpected error.");
throw new ImportFailedException(e.getMessage(),e);
}
}
此方法调用执行多项任务的其他几个组件。这些方法抛出不同的异常。我在这个方法中捕获了所有这些并抛出一个常见的异常。但看起来我需要在此方法中捕获更多异常。所有的 catch 块都做同样的事情。我觉得这不是一个好的设计。
在 Java 6 中是否有更好的方法/模式来处理此类场景中的异常?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)