This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In my Urlybird DB interface i have an unlock method which throws a RecordNotFoundExecption and SecurityException.
Im wondering how should i handle the SecurityException in my service layer? If the exception is thrown in the first place it means that someone is violating the rules of the api. There doesnt seem to be any point bubling this up to the UI layer?
Colin Duggan wrote:There doesnt seem to be any point bubling this up to the UI layer?
You should not handle this exception, because it indicates wrong api usage.
Colin Duggan wrote:Should i just override the DB interface unlock method and replace the SecurityException with a RuntimeException or do i need to handle this??
If you don't want to fail automatically you should not make any changes to the interface you got. In my opinion the SecurityException should be a runtime exception, not a checked exception. Using the search engine of this forum, you'll can find many threads about this topic, e.g. this one.
Colin Duggan wrote:when i say override - i have a custom interface which extends the one supplied by Sun. I think most people have taken this approach. Then in my custom interface i override the unlock method signature
As long as you provide a valid override, you don't have to worry (I followed same approach), but if it's declared as a runtime exception no need to override these methods
Joined: Feb 23, 2008
I was concerned that because the SecurityException appeared in the throws clause of the Sun interface that it had to be declared as checked but declaring as unchecked makes alot more sense.
The other reason I override the method is because i dont want to throw RNFE so my override just looks like this.