(no title)
_ZeD_ | 4 months ago
try {
val user = authService.register(registrationRequest.email, registrationRequest.password)
return user
} catch (exception: Exception) {
// log exception
throw exception
}
no, no, no!the whole point of the exceptions (and moreso of the unchecked ones) is to be transparent!
if you don't know what to do with an exception do NOT try to handle it
that snippet should just be
return authService.register(registrationRequest.email, registrationRequest.password)
CGamesPlay|4 months ago
Both snippets suffer from being too limited. The first, as you point out, catches too many exceptions. But the second.... What happens if the email address is taken? That's hardly exceptional, but it's an exception that the caller has to handle. Your natural response might be to check if the email address is taken before calling register, but that's just a race condition now. So you really need a result-returning function, or to catch some (but probably not all) of the possible exceptions from the method.
noduerme|4 months ago
rockyj|4 months ago