Results 1 to 3 of 3
  1. #1
    tiger100plus is offline Member
    Join Date
    Nov 2008
    Location
    Kuala Lumpur,Malaysia
    Posts
    16
    Rep Power
    0

    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());
    }
    }

    }

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    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

  3. #3
    Deepa is offline Member
    Join Date
    Nov 2008
    Posts
    85
    Rep Power
    0

    Default Re:

    Hi,
    exception.toString() is similar to exception.
    You throws exception instead of Runtime Exception.It depends only upon you.

Similar Threads

  1. Need help on Exception
    By Deon in forum New To Java
    Replies: 7
    Last Post: 02-11-2010, 06:46 PM
  2. Help with Exception
    By bozovilla in forum New To Java
    Replies: 2
    Last Post: 10-19-2008, 06:19 AM
  3. why this exception
    By payal.mitra86 in forum JDBC
    Replies: 1
    Last Post: 05-21-2008, 11:28 PM
  4. Exception!
    By rameshraj in forum Advanced Java
    Replies: 1
    Last Post: 05-05-2008, 02:39 PM
  5. Replies: 1
    Last Post: 03-08-2008, 07:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •