Results 1 to 5 of 5
  1. #1
    killerf2006 is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default About throw message

    Hi all,

    I have an application which throws an exception whenever I use a different input file and I use swing button to run the application. Is it possible to ask the user to input the correct file in a message dialog box to the user whenever the application throws that exception. Now I'm getting the exception message in a console window(Eclipse).

  2. #2
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    When you have function that throws exception and when you are calling it in your program, you must call it in a try / catch block


    for example:
    public void readNextLine() throws IOException {
    // code here
    }

    and when you call it in your program it goes in try/catch block

    try {
    myFile.readNextLine();
    } catch(IOException exception) {
    exception.printStackTrace();
    System.exit(1);
    }

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I think that the OP wants to recursively ask user to enter the correct file name until user enters the incorrect one. In the catch block you repeat the logic that to ask from user to enter the values again.

  4. #4
    killerf2006 is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default

    Hi
    Thanks
    I understood it and it works.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Replies: 6
    Last Post: 06-04-2010, 08:43 PM
  2. what exception to throw
    By DoolinDalton in forum New To Java
    Replies: 5
    Last Post: 02-10-2010, 03:45 PM
  3. throw exception
    By GIRISH PATEL in forum New To Java
    Replies: 4
    Last Post: 04-23-2009, 04:35 AM
  4. throw an exception
    By sfe23 in forum New To Java
    Replies: 3
    Last Post: 02-14-2009, 04:41 AM
  5. Difference between Throws and Throw
    By Poonam in forum New To Java
    Replies: 7
    Last Post: 02-06-2008, 04:52 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
  •