Good question, Ant
I know that you want to throw a database exception, but when this happens, the application in most cases cannot restore its initial state or does not know how to restore it. Thus, this should be handled as a runtime exception . Some problems in database exceptions include
- Error connecting to database
- invalid request
- table or column does not exist
You see that the application cannot restore its initial state. If you consider it possible to restore the original state , to use the application exception . The client will receive the same exception for the application created by your business method. If you want to get the exact exception thrown by your business method, you have two options:
- Use the business delegate template to access EJB
As you know, a runtime exception is wrapped with an EJBException, so you can use something like
Suppose you have this bean-free session
@Stateless public class BeanImpl implements Bean { public void doSomething() { try {
So you end the bean session through the business delegate
public class BeamBusinessDelegate implements Bean {
Or you can extend an EJBException to suit your needs
public class DatabaseException extends EJBException { }
So, in your business method
@Stateless public class BeanImpl implements Bean { public void doSomething() { try {
Yours faithfully,
source share