Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Exception Handling

  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    271
    Thanks
    21
    Thanked 7 Times in 7 Posts

    Question Exception Handling

    Hello all,

    First of all sorry for the indescriptive title, but I don't really know if the issue is with code or IDE, and rather why it's happening.

    Qustion: Why is this giving me an error? I'd expect that I should be able to print the name of the exception with out issues with this code.
     
    try{
    //code
    }catch (Exception e){
    	System.out.println("Error .. " e.toString());//line 25
    }
     
    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Syntax error on token "e", delete this token

    at HR20ID3Reader.main(HR20ID3Reader.java:25)




    Eclipse suggests that I use this code instead:

    try{
    //code
    }catch (Exception e){
    	System.out.println("Error .. " .toString());//line 25
    }
     
    Error .. 



    This output is lacking the name of the exception.

    -Mel
    Last edited by Melawe; December 20th, 2011 at 07:45 PM. Reason: bb code


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Exception Handling

    System.out.println("Error .. " e.toString());

    String addition...I believe you want to add the 2 strings together?

    "Error..." + e.toString()

    You might consider using the e.printStackTrace() as it provides a lot more detail as to the exception, which oftentimes comes in very handy

  3. #3
    Member
    Join Date
    Mar 2010
    Posts
    271
    Thanks
    21
    Thanked 7 Times in 7 Posts

    Default Re: Exception Handling

    Quote Originally Posted by copeg View Post
    System.out.println("Error .. " e.toString());

    String addition...I believe you want to add the 2 strings together?

    "Error..." + e.toString()
    X( How did I miss that. Thanks copeg!

    Quote Originally Posted by copeg View Post
    You might consider using the e.printStackTrace() as it provides a lot more detail as to the exception, which oftentimes comes in very handy
    Thanks, thats the first time i've heard of the method, it will be very help full with exception handling.

    -Mel

Similar Threads

  1. [SOLVED] exception handling
    By Topflyt in forum Exceptions
    Replies: 5
    Last Post: December 22nd, 2011, 12:00 PM
  2. Exception handling
    By JavaGirl9001 in forum Object Oriented Programming
    Replies: 1
    Last Post: November 26th, 2011, 08:45 PM
  3. Exception Handling
    By hello_world in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 5th, 2011, 05:47 PM
  4. Need help with exception handling for a string
    By toppcon in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 6th, 2011, 06:59 AM
  5. Exception handling
    By AnithaBabu1 in forum Exceptions
    Replies: 6
    Last Post: August 27th, 2008, 09:37 AM