1

I have a problem using a variable surrounded with a try : Here's the beginning of my method :

public static word[] countWords(String text) {
    try {
            text = Preprocesseur.preprocess(text);
    } 
    catch (IOException e) {
            System.out.println("Error méthod countWords");
            e.printStackTrace();
    }    

Actually i need to use the String text (preprocessed) several line after, but java doesn't affect the value Preprocesseur.preprocess(text) to the whole method --> it stays in the try/catch block

I was wondering : how to call my method Preprocesseur.preprocess and affect its return String to the whole countWords method ? Because a try/catch block is required (or throws declaration which leads to the same result)

David Pilkington
  • 13,528
  • 3
  • 41
  • 73

1 Answers1

0

You can simply switch from catching exceptions to throwing them higher form your method and deal with your problems later, like this:

public static word[] countWords(String text) throws IOException {
        text = Preprocesseur.preprocess(text);
}
TheMP
  • 8,257
  • 9
  • 44
  • 73