• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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.
 
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic