Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-25-2008, 03:16 PM
Member
 
Join Date: Nov 2008
Location: Kuala Lumpur,Malaysia
Posts: 16
Rep Power: 0
tiger100plus is on a distinguished road
Send a message via MSN to tiger100plus
Question 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());
}
}

}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-26-2008, 01:43 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-27-2008, 08:45 AM
Member
 
Join Date: Nov 2008
Posts: 85
Rep Power: 0
Deepa is on a distinguished road
Default Re:
Hi,
exception.toString() is similar to exception.
You throws exception instead of Runtime Exception.It depends only upon you.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help on Exception Deon New To Java 7 02-11-2010 06:46 PM
Help with Exception bozovilla New To Java 2 10-19-2008 06:19 AM
why this exception payal.mitra86 Database 1 05-21-2008 11:28 PM
Exception! rameshraj Advanced Java 1 05-05-2008 02:39 PM
Trouble with factory method - unhandled exception type Exception desmond5 New To Java 1 03-08-2008 07:41 PM


All times are GMT +2. The time now is 03:58 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org