如何将SQLException包装到未选中的一个? [英] How should I wrap a SQLException to an unchecked one?

查看:159
本文介绍了如何将SQLException包装到未选中的一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都知道SQLException是一个检查的异常,我们大多数人同意检查的异常是冗长的,导致扔/捕获污染。



我应该选择哪种方法避免SQLException抛出?
推荐哪个包装/技术/库?
(例如Spring的PeopleAccessException,但我不想使用Spring)

解决方案

它作为新的RuntimeException(jdbce)。或者限制你自己的扩展运行时异常的异常并使用它。我不认为在这里需要任何框架。甚至春天都会在每次需要它时检查异常。


We all know that SQLException is a checked Exception and most of us agree that checked Exception are verbose and leads to throw/catch pollution.

Which approach should I choose to avoid SQLException throwing? Which wrapper/technique/library is recommended? (for example DataAccessException for the Spring folks, but I don't want to use Spring)

解决方案

Just wrap it as new RuntimeException(jdbce). Or defince your own exception that extends runtime exception and use it. I do not think that any framework is required here. Even spring wraps checked exceptions by unchecked every time it needs it.

这篇关于如何将SQLException包装到未选中的一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆