Thursday, July 19, 2007

Geoff Jansz Baked Cheesecake Recipe

Unchecked? Checked?

use Checked or Unchecked Exception ..

All very sensible arguments and which can be used to make yet another examination of conscience:
1 - but "checked exception" are useful or are a nuisance?
2 - but if I find any time to do try .. catch, how many times it is the fault of the language and how many times my fault?
(actually the start of the speech was "since the checked are cumbersome when trying to define a construct of closures, is that maybe this means that the case get rid of it?" .. A I do not know this answer ..)


My position is "borrowed" (read: copied :-) Article Effective Java Exceptions
In this view, one should distinguish between "unforeseen conditions" (default) and "rare conditions (contingencies) modeling the first with exceptions" unchecked "and the latter with conditions" checked ".

By the way .. (But maybe I was back)
An example they are using to make the reasoning is as follows:

public User login (String username, char [] password) throws LoginFailedException

What puzzles me is that one of mantra of the exceptions that I learned (I think it was from Effective Java) "Use exceptions for exceptional circumstances."

But it is unusual for a user types the wrong password? or write to the wrong audience?
In this case I expect that the return value gives the information if the login is correct or not (ie a value User.UNAUTHENTICATED to say "no, you have not been authenticated").

For me, the statement would be:

public User login (String username, char [] password)

The login could return a UserRepositoryFaultException (unchecked) when they can not or has trouble connecting with your DB, LDAP (but would not make sense to expose a SQLException or LDAPException).

But then, when it 'which I will use the checked? When I know I can do using the API operation to resolve the rare condition. Later for an example ... This time

0 comments:

Post a Comment