Results 1 to 3 of 3
Thread: Exception:Meaning
- 11-25-2008, 02:16 PM #1
Member
- Join Date
- Nov 2008
- Location
- Kuala Lumpur,Malaysia
- Posts
- 16
- Rep Power
- 0
Exception:Meaning
dear helpers,
1)What means exception.toString() and why must use throws Runtime Exception rather than the catch statement based on this program...?
public class Test {
public static void method3()throws RuntimeException{
throw new RuntimeException("RuntimeException occured in method3");
}
public static void method2()throws RuntimeException {
try{
method3();
}catch(RuntimeException exception){
System.out.printf("The following exception occured in method2\n%s\n",exception.toString());
throw exception;
}
}
public static void method1()throws RuntimeException{
try{
method2();
}catch(RuntimeException exception){
System.out.printf("The following exception occured in method1\n%s\n",exception.toString());
throw exception;
}
}
public static void main(String[] args){
try{
method1();
}
catch(RuntimeException exception){
System.out.printf("The following exception occured in main\n%s\n",exception.toString());
}
}
}
- 11-26-2008, 12:43 AM #2
It is actually your choice to use Rutime exception of Exception, one has compiler make sure you deal with them, other lets it go.
toString() is to get someting that will print normally.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 11-27-2008, 07:45 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 85
- Rep Power
- 0
Similar Threads
-
Need help on Exception
By Deon in forum New To JavaReplies: 7Last Post: 02-11-2010, 05:46 PM -
Help with Exception
By bozovilla in forum New To JavaReplies: 2Last Post: 10-19-2008, 05:19 AM -
why this exception
By payal.mitra86 in forum JDBCReplies: 1Last Post: 05-21-2008, 10:28 PM -
Exception!
By rameshraj in forum Advanced JavaReplies: 1Last Post: 05-05-2008, 01:39 PM -
Trouble with factory method - unhandled exception type Exception
By desmond5 in forum New To JavaReplies: 1Last Post: 03-08-2008, 06:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks