This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

core java

 
vijay deivasigamani deivasigamani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a doubt, can we return an exception to a method? if so give me an example.
 
Jim Hardin
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this question belongs in "Java >> Java in General (beginner)"
instead of "Products >> Struts". That said, if I understand your question, I think you're looking for:

See also Sun Exceptions Tutorial.
-Jim
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, a method can return any type, also an Exception.

This:

returns an Exception, but it does not throw one. Output is
java.lang.Exception: Eeks !


Yours,
Bu.
 
vijay deivasigamani deivasigamani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Burkhard Hassel , Jim Hardin

Thanks for your reply and cleared with the doubt.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic