如何将SQLException包装到未选中的一个? [英] How should I wrap a SQLException to an unchecked one?
问题描述
我应该选择哪种方法避免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屋!