Results 1 to 6 of 6

Thread: printing errors

  1. #1
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default printing errors

    i would like to print error messages from another class for my program. i was thinking of either returning an array of errors if there are any, but then i heard about try/catch statements. i am checking if files exist. what would be the best way to go about this? i wasn't sure if i could use a try statement to check if two files do not exist... i was thinking about an if statement (which is what i'm currently using). i like how the try/catch statements give off a red error message though. and is there a way with the catch statements, that i could put them together, if there is more than one error (an array of e's [or exceptions])?

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: printing errors

    File has a method to check if it exists or not. Check out the File docs. There is also a FileNotFoundException that can be thrown FileNotFoundException (Java Platform SE 6)

  3. #3
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default Re: printing errors

    would you print the error(s) to an array, or use the exceptions?

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: printing errors

    I would probably check if the file exists and if not then throw the FileNotFoundException. It depends though, do you want to kill the program if the file doesn't exist or do you want to create the file if it doesn't exist. I would probably stay away from the arrays.

  5. #5
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default Re: printing errors

    i just like the arrays because they are a little more customizable (with the error messages). also, i am checking more than one file. is that a problem with exceptions, or can you combine them together?
    it just seems that the standard file not found exception isn't as user-friendly.

  6. #6
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: printing errors

    You can pass a message to the FileNotFoundException constructor which will print out.

    psuedo code

    if Not file.exists
    throw new FileNotFoundException("No file")

Similar Threads

  1. Replies: 9
    Last Post: 08-19-2011, 01:59 AM
  2. printing string backwards and printing every other
    By droidus in forum New To Java
    Replies: 22
    Last Post: 03-10-2011, 10:17 AM
  3. Replies: 4
    Last Post: 01-04-2011, 01:36 AM
  4. Help with three errors -.-
    By Insomniac Riot in forum New To Java
    Replies: 5
    Last Post: 03-30-2010, 07:52 PM
  5. Replies: 3
    Last Post: 03-08-2009, 02:51 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
  •