• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't callbacks throw checked exceptions?

 
Mellon Sun
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lifecycle callback interceptor methods may throw system runtime exceptions, but not application exceptions. Which container are you using ?
 
Mellon Sun
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glass Fish V2 in NetBeans 6.5.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I reproduced it too. It doesn't look very spec friendly, does it ?
 
Chaminda Amarasinghe
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic