我有EJB类,自定义异常和Web后端bean类,如果EJB传递异常,我想在Web中捕获自定义异常,但RuntimeException
捕获异常?
异常类:
@ApplicationException
public class CustomException extends Exception { }
EJB类:
public class EmployeeDao {
private UserTransaction transaction;
@PersistenceUnit(unitName="xxx")
protected EntityManagerFactory entityManagerFactory;
. . . . .
public void addNewEmployee(Employee employee) throws CustomException {
. . . .
throw new CustomException (...);
}
}
后端类:
public class EmployeeBackend {
. . . .
public void doAddEmployee() {
try {
....
employeeDao.addNewEmployee();
} catch(CustomException e) {
System.err.println("------------------------ CustomException");
e.printStackTrace();
} catch(RuntimeException e) {
System.err.println("------------------------ RuntimeException ");
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
问题是在我使用自定义Exception覆盖主Exception之后,会发生系统异常,因此自定义异常没有通过,只有系统异常通过:)