I've a CMP local entity bean with a findbyName method, which throws a FinderException. I've a session bean implements the session facade design pattern calls the findByName method in the local entity bean. It's better for me to:
1. Catch the FinderException and return null Or?
2. Let the FinderException bubble up to the client (which is a business delegate) to handle it Or?
3. Catch the FinderException and wrap another application exception around it?
Either of the three may be used, depending on the circumstances.
The way I use this pattern, clients of the session facade ask the facade to perform a particular task. Therefore, the client should get back an exception (or return value) that would make sense in terms of that task. For instance:
- If the client asks the facade to make sure a new account with a given user name can be added, the facade needs to make sure the user name doesn't exist allready. In that case, the facade should catch the FinderException indicating no such user exists and return normally.
- If the client asks the facade to return the value object of a specific user account and the facade fails to find it, a FinderException makes sense to the client and can be thrown to it.
- If the client asks the facade to process some large order, and the processing involves finiding and validating a lot of data, a FinderException won't make any sense for the client. The client shouldn't know the particular details of how the order processing works. So, in that case, I would throw an OrderProcessingException instead of a FinderException.
In most of the cases there is no clear-cut choice. It usually comes down to personal style.