Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I wrap a SQLException to an unchecked one?

We all know that SQLException is a checked Exception and most of us agree that checked exceptions are verbose and lead 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)

like image 743
MRalwasser Avatar asked Oct 15 '25 04:10

MRalwasser


1 Answers

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.

like image 82
AlexR Avatar answered Oct 16 '25 16:10

AlexR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!