• 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

RuntimeException(PL Help)

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear friends,
1. Are all RuntimeExceptions thrown only at runtime? Do all Runtime Exceptions have a default handler because of which a compile time error never occurs ? . I mean the result is only a RunTimeException.
Are there any cases when the defualt handler doesn't work in the case of RunTimeException and an compile error is thrown?
2.
Do all checked exceptions throw a compile time error (and not runtime) if not caught by using try, catch or using throws? please explain.
3. Even in many checked exception even though I specified throws I had to still put a try catch in the caller of the method . If i don't give a try catch in the caller of the method , a compile time error still occurs.
I just wanted to confirm this point.
4. Is it true that try cannot be used on a single statement?
Thanks in advance
Padmini
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. the runtime exception by default are handled by the run time engine and thus the compiler never bothers u to specify a try catch block.
2. the method has to completly handle all compile time exceptions or specify in the throws clause. This help the programmer using the interface to be aware of the things which a method can return.
3. i am not sure.. Any example..
4. why not ..
We all use
try {
BufferedReader br = new BufferedReader(new FileInputStream("file.txt"));
} catch (IOException e) {
System.err.println(e.getMessage());
}
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


3. Even in many checked exception even though I specified throws I had to still put a try catch in the caller of the
method . If i don't give a try catch in the caller of the method , a compile time error still occurs.
I just wanted to confirm this point.


Yes, if a method throws an Exception, then the statement which calls the method must be enclosed in a try-catch (or the method enclosing the statement which calls the original method must itself declare that it throws the exception). All checked Exceptions must be caught somewhere within a program or else thrown all the way up the calling chain to the JRE.
 
padmini Babu
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Scott Appleton:
Yes, if a method throws an Exception, then the statement which calls the method must be enclosed in a try-catch (or the method enclosing the statement which calls the original method must itself declare that it throws the exception). All checked Exceptions must be caught somewhere within a program or else thrown all the way up the calling chain to the JRE.



********
Thanks scott and Anand.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic