aspose file tools *
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes RuntimeException(PL Help) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "RuntimeException(PL Help)" Watch "RuntimeException(PL Help)" New topic
Author

RuntimeException(PL Help)

padmini Babu
Ranch Hand

Joined: Feb 10, 2001
Posts: 103
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
anand raman
Ranch Hand

Joined: Jun 06, 2001
Posts: 66
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());
}
Scott Appleton
Ranch Hand

Joined: May 07, 2001
Posts: 195

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

Joined: Feb 10, 2001
Posts: 103
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RuntimeException(PL Help)