java – PMD错误 – AvoidThrowingRawExceptionTypes

weixin_38061732 2019-09-12 12:51:16
我有一个类如下,当我运行PMD规则时,我得到了类型为AvoidThrowingRawExceptionTypes的PMD警报.我无法解决这个问题,因为当我在构造函数throws子句中添加任何其他异常类型时,我会收到错误 new PersistenceManager(CommonConstants.IP_DB) 怎么解决这个?有人可以帮我吗? public class PersistenceManager implements CommonConstants { ..... /** * Stores the persistence mgr for IPMasterData_DB */ public static PersistenceManager IPMasterData_DB = new PersistenceManager( CommonConstants.IP_DB); /** * Configures the data source according to the resource passed. * * @param dbName * Databasename */ protected PersistenceManager(String dbName) throws Exception{ String resourceName = ""; if (LOGGER == null) { LOGGER = Logger.getLogger(PersistenceManager.class); } try { resourceName = getConfigFileName(dbName); this.sessionFactory = new Configuration().configure(resourceName) .setProperty("hibernate.jdbc.batch_size", PersistenceManager.getBatchSize(dbName)) .buildSessionFactory(); } catch (HibernateException ex) { ex.printStackTrace(); LOGGER .error("Exception building SessionFactory for configKey ", ex); throw new RuntimeException(ErrorConstants.SESSIONFACTORY_BUILD, ex); } } }
...全文
632 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38066448 2019-09-12
  • 打赏
  • 举报
回复
抛出专门的异常而不是泛型异常是一种很好的编程习惯. PMD可以检测并建议您,这正是已经完成的工作. 将异常包装在一个专门的异常中并抛出它而不是抛出一个RuntimeException实例.

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧