Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock question

 
Sandhya Lever
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given

7. try {
8. msb.calculateloan(30,12000.00,6.5);
some code here
}
11. catch(java.rmi.NoSuchObjectException ex1){
12. //exception handling code here
13. }catch(javax.ejb.EJBException ex2) {
14. //ecxeption handling code here
15. }catch (javax.transaction.TransactionRequiredException ex3){
16. //exception handling code here
17. }catch(java.rmi.RemoteException ex4) {
18. //exception handling code here
19. }
Which line will never be reached assuming msb is a reference to a stateful session beans remote component interface?
a)12
b)14
c)16
d)18
Thanks in advance
 
Rahul Mishra
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 14 will never be reached. Since your client is remote...EJB Exceptions are never thrown to remote clients.EJB Exceptions propogate as RemoteExceptions to remote clients.

The only other possible SCJP Trick here was trying to catch a super class Exception first and then its sub class. But in this case that doesn't hold true. The Hierarchy is maintained here.All sub classes first and then the super class(Remote Exception)
 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think (d) will be answer.(line 18). Because bean can never ever throw RemoteException.
 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think (d) will be answer.(line 18). Because bean can never ever throw RemoteException.


But the container can throw the RemoteException back to the client.

Example is, (from Table 15, Spec page 376) let say the method calculateloan in the above question, executes in a transaction started by Container and the method throws system exception, then container will catch this system exception, log it, rollback txn, discard instance and throw RemoteException back to client. Imran or others, correct me if this is wrong.

So, from the point of view of the Remote Client, the Remote client can actually receive the RemoteException.

I would go with answer b (line 14). The reason I think this is correct is, a bean can actually throw the EJBException (spec page 373), but the container would not pass this EJBException back to the remote client (Table 15 & 16, spec pages 375, 376, 377), so I think a remote client would never get the EJBException.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic