Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Throwing exception in EJB  RSS feed

 
Anup Katariya
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If my remote interface method is throwing some exception ( i.e public String getString() throws SomeException; ) then do i need to put that throws clause in my bean method ?
please justify the answer.
 
Volodymyr Shram
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anup Katariya:
If my remote interface method is throwing some exception ( i.e public String getString() throws SomeException; ) then do i need to put that throws clause in my bean method ?
please justify the answer.

It's up to you. If you wnat to handle your method's exceptions inside the bean, you do not need to throw this exepion "forward". For example in bean's method:

There is no any throws.
But, as for me, it is better practice to throw on your server exceptions to client via throws clause and to handle this exceptions on the client side:

where YourServerException is your exception class that extends Exception and, of course, implements java.io.Serializable
But anyway, it's up to you to choose one of this ways.
Regards.
 
Anup Katariya
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I should have been very specific.
I was talking about RemoteException. which is
there in methods of remote interface, but you dont need specify it for implemented methods in bean.
why is it so?
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posted by Anup Katariya
I was talking about RemoteException. which is
there in methods of remote interface, but you dont need specify it for implemented methods in bean.
why is it so?

The answer is no you don't need/want to throw a RemoteException from the implementation class. In fact, if you want your ejb to have both remote and local interfaces you can't declare a RemoteException as being thrown by your implementation class.
Remote Exceptions occur because of network transport problems and are thrown by the server generated stubs, this is why they need to be declared in your remote interface. The stub is going to implement that interface.
[ October 30, 2002: Message edited by: Chris Mathews ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!