Zdravím,
potřebuji poradit, jak zapsat vyjímku v metodě do seznamu. Můj program zatím vypadá takto:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
public class CaesarCypher extends Cypher {
private String fileName;
protected String readFileContent(String sourceFileName) {
String fileName = "vstup.txt";
BufferedReader in = null;
StringBuilder content = new StringBuilder();
String line, text;
try {
in = new BufferedReader(new FileReader(fileName));
while((line = in.readLine()) != null) {
content.append(line);
content.append("\n");
}
} catch (FileNotFoundException ex) {
System.out.println("File with name " + fileName + " was not found: " + ex.toString());
} catch (IOException ex) {
System.out.println("Failed to read file " + fileName + " :" + ex.toString());
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ex) {
System.out.println("Failed to close file " + fileName + " :" + ex.toString());
}
}
}
text = content.toString();
return text;
}
protected String crypt(String content, int key) {
StringBuilder cryptedText = new StringBuilder();
for (int i = 0; i < content.length()-1; i++) {
cryptedText.append((char)(content.charAt(i) + 2));
}
return cryptedText.toString();
}
}
A já mám každou chybu, která v metodě vznikne zapsat do seznamu (List<String>) chyb. Tento seznam chyb lze pak zjistit voláním metody getAllErrors().
Díky za pomoc.