• 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

Exception Handling

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have doubt in throws and throw keyword .can anyone briefly explain me
when throws is used in compile time or run time exception and throw is compile or runtime exception
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keyword throw is used to, well, throw an exception, which can be either checked or unchecked (RuntimeException). Whenever a checked exception is thrown (either explicitly, or calling some method that might throw it), the method has to either:
1) handle the exception in a catch { }, or
2) declare to throw that exception via the keyword throws
Unchecked (runtime) exceptions need not be declared with throws.
Which of the two you need to do in a specific method depends on the responsibilities: which part of the program is responsible for handling what kind of exception. When you declare with throws, the method is saying: "anybody calling me should know that I may throw exceptions such and such, so take due measures". The calling method will either handle it or let it propagate further up the call stack.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic