wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Can't callbacks throw checked exceptions? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Can Watch "Can New topic
Author

Can't callbacks throw checked exceptions?

Mellon Sun
Ranch Hand

Joined: Feb 20, 2003
Posts: 126
I write this in a stateless session bean:
@PostConstruct
public void postContruct() throws Exception{
System.out.println("This is PostContruct method defined in bean class.");
throw new Exception();
}

the bean can be compiled and run well.
See, here is the output:
This is PostContruct method defined in bean class.
java.lang.Exception
at com.mellon.StatelessSBBean.postContruct(StatelessSBBean.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)


Books I read say callbacks cannot throw checked exceptions, what's wrong then?

[ December 07, 2008: Message edited by: Mellon Sun ]
[ December 07, 2008: Message edited by: Mellon Sun ]

SCJP,SCWCD1.3,SCWCD1.4,SCJD,SCBCD5,SCEA5
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Lifecycle callback interceptor methods may throw system runtime exceptions, but not application exceptions. Which container are you using ?


[My Blog]
All roads lead to JavaRanch
Mellon Sun
Ranch Hand

Joined: Feb 20, 2003
Posts: 126
Glass Fish V2 in NetBeans 6.5.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Yes, I reproduced it too. It doesn't look very spec friendly, does it ?
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
Yes I also have similar experience. GF is the closest to spec but not perfect. my doubt is why GF that a product of Sun, even cant follow the spec.
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356
Hello,

all of you are right. But to me one thing is still unclear after reading the spec: What should the CONTAINER PROVIDER do about such obviously invalid implementations of callback lifecycle interceptor methods? Error in the verifier (did anyone try that?), error at deployment time, error at runtime, but with a different error message?

What do we want?

Kai


Kai Witte's business website Kai Witte's private homepage
 
jQuery in Action, 2nd edition
 
subject: Can't callbacks throw checked exceptions?
 
Similar Threads
help me to understand compiletime & runtimr exceptions
Why doesn't EJBContext offer a method like getCallerRole to obtain the caller's role?
is HFEJB contradictory?
Checked application exception
Whizlabs Exam Simulator