我想知道在 JavaEE 6 中捕获的最佳方法是什么OptimisticLockException
。我有以下 EJB:
@Stateless
public class SeminarBooking {
public void bookSeminar(Long seminarId, int numberOfPersons) {
...
//check capacity & do booking
//OptimisticLockException can occur in this method
}
这是我的 REST 接口:
@Path("/seminars")
@Produces("application/xml")
@Stateless
public class SeminarResource {
@GET
@Path("{id}/book")
public Seminar bookSeminar(@PathParam("id") Long id, @QueryParam("persons") Integer persons) {
try {
seminarBooking.bookSeminar(id, persons);
return seminarBooking.getSeminar(id);
}
catch(Exception e) {
//why is this never called?
logger.error(This will never happen, e);
throw new WebApplicationException(e);
}
}
在 REST 接口中,我捕获了所有异常,此外,我看到OptimisticLockException
如果我从浏览器调用接口,那么为什么 catch-Block 从未执行?