Results 1 to 14 of 14
  1. #1
    minifish is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Exclamation handle FileNotFoundException

    'm calling a method that need to open up the af.sh file.
    Because the file does not exist, I get error:

    java.io.FileNotFoundException: \file\af.sh (The system cannot find the path specified)

    I can't change this method but I want to run all other parts of the method.
    Is there anything I can do to catch this exception while continue running the method?

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

    Default

    Use try-catch block to catch that exceptions and once you get that handle it according to your requirements.

  3. #3
    racerxadam is offline Member
    Join Date
    Jul 2008
    Posts
    68
    Rep Power
    0

    Default

    if you can't change the method that throws the FileNotFoundException at all, I don't see how you can execute lines that are past where the exception is thrown. Why not create the file even if it is empty?

  4. #4
    minifish is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    I get
    Unreachable catch block for FileNotFoundException. This exception is never thrown from the try statement body

    when I do

    try {
    _help= new HelpMethod();
    }catch(FileNotFoundException e){

    }

    It's try to create a log when I'm making HelpMethod, but I dont want the log to be made and I can't change the HelpMethod Class.
    Any suggestion will be great,

    Thank you

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

    Default

    This exception is never thrown
    That says the code in the try block does NOT throw that exception.
    One solution is to change the catch to be for Exception and then look at what type it is.

  6. #6
    minifish is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    That says the code in the try block does NOT throw that exception.
    One solution is to change the catch to be for Exception and then look at what type it is.
    try {
    _help= new HelpMethod();
    }catch(Exception e){
    System.err.println("ERROR");
    }

    does not catch any exceptions.
    and I'm still getting java.io.FileNotFoundException:... (The system cannot find the path specified)

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

    Default

    Can you post the FULL text of the error message? I need to see it all.

  8. #8
    minifish is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    log4j:ERROR setFile(null,true) call failed.
    java.io.FileNotFoundException: \file (The system cannot find the path specified)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)

    Thank you soo much

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

    Default

    Is that all of it? I don't see the call to HelpMethod() in that message.
    How are you executing the program? Can you open a console and enter: java ... to execute it? ... depends on if the classes are in a jar file or in folders.

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

    Default

    Quote Originally Posted by minifish View Post
    try {
    _help= new HelpMethod();
    }catch(Exception e){
    System.err.println("ERROR");
    }

    does not catch any exceptions.
    and I'm still getting java.io.FileNotFoundException:... (The system cannot find the path specified)
    That means, your code doesn't throw any exception. Even on your full error message cannot see that, if that's the whole error message you get, HelpMethod() cause for this. Did you debug and try to find where the error is?

  11. #11
    minifish is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Sorry this is the full error message.
    I know the log is created in ToolHelpMethod.class but I'm not allowed to change that class.

    log4j:ERROR setFile(null,true) call failed.
    java.io.FileNotFoundException: \file (The system cannot find the path specified)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at org.apache.log4j.FileAppender.setFile(FileAppender .java:272)
    at org.apache.log4j.RollingFileAppender.setFile(Rolli ngFileAppender.java:156)
    at org.apache.log4j.FileAppender.activateOptions(File Appender.java:151)
    at org.apache.log4j.config.PropertySetter.activate(Pr opertySetter.java:247)
    at org.apache.log4j.config.PropertySetter.setProperti es(PropertySetter.java:123)
    at org.apache.log4j.config.PropertySetter.setProperti es(PropertySetter.java:87)
    at org.apache.log4j.PropertyConfigurator.parseAppende r(PropertyConfigurator.java:645)
    at org.apache.log4j.PropertyConfigurator.parseCategor y(PropertyConfigurator.java:603)
    at org.apache.log4j.PropertyConfigurator.configureRoo tCategory(PropertyConfigurator.java:500)
    at org.apache.log4j.PropertyConfigurator.doConfigure( PropertyConfigurator.java:406)
    at org.apache.log4j.PropertyConfigurator.doConfigure( PropertyConfigurator.java:432)
    at org.apache.log4j.helpers.OptionConverter.selectAnd Configure(OptionConverter.java:460)
    at org.apache.log4j.LogManager.<clinit>(LogManager.ja va:145)
    at org.apache.log4j.Logger.getLogger(Logger.java:94)
    at org.apache.commons.logging.impl.Log4jFactory.getIn stance(Log4jFactory.java:145)
    at org.apache.commons.logging.LogFactory.getLog(LogFa ctory.java:345)
    at Discovery.<clinit>(Discovery.java:52)
    at ToolHelpMethod.<init>(ToolHelpMethod.java:53)
    at tool.main(tool.java:32)

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

    Default

    Seems this is something wrong with the log4j. How did you configure log4j in your application?

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

    Default

    The code you posted:
    try {
    _help= new HelpMethod();
    }catch(Exception e){
    System.err.println("ERROR");
    }
    Does not agree with the error message you posted. There should be a reference to the method: HelpMethod() in the log message.
    I don't see it.
    So I don't know that the code that you posted is being executed when the error occured.

    at Discovery.<clinit>(Discovery.java:52)
    at ToolHelpMethod.<init>(ToolHelpMethod.java:53)
    at tool.main(tool.java:32)
    What code is at the lines referenced above? It shows 3 source files.

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

    Default

    At least debug and see from the beginning. So you can find it very easily. Start from the beginning. As Norm says there is no connection with your error message and with the code segment you have post here. For me, it's something wrong with log4j, you have used in your application.

Similar Threads

  1. Replies: 22
    Last Post: 04-09-2011, 05:59 AM
  2. java.io.FileNotFoundException
    By thevoice in forum New To Java
    Replies: 5
    Last Post: 06-13-2008, 09:38 AM
  3. Better way to handle exceptions
    By javaplus in forum Advanced Java
    Replies: 2
    Last Post: 01-16-2008, 07:47 PM
  4. FileNotFoundException
    By PeonLover in forum New To Java
    Replies: 1
    Last Post: 12-26-2007, 07:15 AM
  5. how to handle exceptions
    By paty in forum Advanced Java
    Replies: 2
    Last Post: 08-05-2007, 05:17 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
  •