• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Throws and throw

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
difference between throws ,throw and throwable
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

difference between throws ,throw and throwable



A method THROWS exception(s)
You throw an exception explicitly using THROW
Throwable is a super class of all exceptions / errors
 
Confused
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks chetan.
but tell me one thing,
suppose i have a method called calculation() and that method is in a
try/ catch block and if any error occurs within that method then catch will show me the error like ArithmethicException ...something like that
and it is an example of throw ... which is happening implicitly ...
am I right ?

and when I want any of my method will throw me a particuler exception that time I can invoke a method like this

double calculation throws ArithmethicException()
{
}
am I right ...
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Piyali:

Yes, basically:



Of course, the code above is a bit silly; Throwables include Errors as well, not just Exceptions, so it may not be useful to catch them. Also, ArithmeticException is a runtime exception (descendant of RuntimeException), so it is not required to declare it in the method header. But doing so is a good idea, because the user of your API will get a better overview of what's happening.
 
Confused
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David !
:-)
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But normally you don't declare your RuntimeExceptions in the method header. Instead you declare them in the method's javadoc. See java.util.Vector for instance:


Otherwise your API will be polluted with RuntimeExceptions that the clients of the API normally shouldn't be catching anyway.
[ November 28, 2006: Message edited by: Mattias Ahlin ]
reply
    Bookmark Topic Watch Topic
  • New Topic