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: Help required, I do not understand how to do this Exception?

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help required, I do not understand how to do this Exception?

    Hi,

    I have to complete this question

    " Handling exceptions
    Write a program that reads integers in from a file, adds them up (you don’t need to store them just read the number add it to the total and move to the next number) and displays the total. Make this work before you try to handle any exceptions that may happen.

    Once you have the above working – try the following

    Firstly check for a missing file – can you catch that error and print out a suitable error message. Check it works – change the file name to an invalid one and run – what happens?

    Then try handling incorrect data in the file – what if there is a double or a string in the file – can you stop the programming crashing and end the program? What is the best way to do this? Then test it works – put some invalid data in the file and run the program again – what happens?
    "

    I am really unsure which kind of exception or what It is I need to be doing,
    Thanks!


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Help required, I do not understand how to do this Exception?

    If you run your code with a bad file name, the JVM will show you exactly what exception you should be catching. Same for the file having bad data. Why not try this and see what exceptions the JVM gives you.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help required, I do not understand how to do this Exception?

    I think I understand what you're saying, thank you, I'll try that.

Similar Threads

  1. help required !
    By arvindbis in forum Web Frameworks
    Replies: 0
    Last Post: October 8th, 2011, 02:17 AM
  2. Replies: 6
    Last Post: March 25th, 2011, 04:42 PM
  3. Help Required
    By javajim in forum Java Networking
    Replies: 0
    Last Post: March 4th, 2010, 09:48 AM
  4. Help required Please
    By nandhini in forum AWT / Java Swing
    Replies: 1
    Last Post: December 4th, 2009, 09:55 AM