Results 1 to 5 of 5
  1. #1
    navya4u2004 is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default Handling errors

    what are the option of handling errors in java?
    Last edited by navya4u2004; 08-10-2011 at 06:48 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by navya4u2004 View Post
    Below is my code so far but that i having trouble with below three.
    First please tell us exactly what trouble you're having. Note that the more specific your question usually the more specific and helpful the answer.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by navya4u2004 View Post
    Hello,My main questions are how do I:
    1.) Remove space if user add in front or at end of the data, ie, " Bob,Hope,1000 ". In my input.trim() is not working, when space is added at the end of input.
    Hm this is curious because it should work, and when I test it, it works fine for me. Can you show us exactly how are you trying to use trim()?

    2.) Using a single try-catch construct, handle all the different exceptions explicitly and print out the exception message. (I'm not sure if i have entered all the catch exception)
    The Java compiler will tell you if you are missing any catch blocks.


    3.) when Cancel is clicked how do I close dialog box,
    JOptionPane should take care of this for you. If not, what specific problems are you having?


    4.) If when only the first name is entered, when only the first name and the last name are entered. How do I enter exception these kind of error handling since all three data is needed
    What do you mean by "enter exception"? What have you tried? Are you allowed to use the String#split(...) method?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    1) where do you see that trim() is not working?
    Try this statment:
    Java Code:
           System.out.println(">" + "   A msg   ".trim() + "<");        // >A msg<

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    The trim() method returns a new String.

    Your code should be something like:

    Java Code:
    String text = "abcd    ";
    text = text.trim();
    Now you can parse the text variable.

Similar Threads

  1. Handling input - multiple keys pressed
    By Shadowstrike in forum Advanced Java
    Replies: 3
    Last Post: 12-30-2010, 02:47 PM
  2. Handling Errors IE: Wrong User Input
    By movsesinator in forum New To Java
    Replies: 4
    Last Post: 04-06-2010, 02:37 AM
  3. how to avoid input errors?
    By Sinnergy in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 12:25 AM
  4. Runtime.exec(), handling input and output streams
    By crookshank in forum New To Java
    Replies: 0
    Last Post: 06-05-2008, 03:41 PM
  5. Handling SQL Errors and Warnings
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-12-2008, 10:37 AM

Posting Permissions

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