• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Throwing exception in EJB

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic