Hello,
I want to use try and catch for the situations where is no text file to be found.
Sadly I can not get it to work. It is is not catching at all. can someone tell me how this works?
thank you very much :)
- BufferedReader reader;
String line;
void setup() {
// Open the file from the createWriter() example
try {
reader = createReader("not_there.txt");
}
catch (Exception e) {
e.printStackTrace();
println("No file found"); // this should be displayed
}
}
void draw() {
if (dok) {
try {
line = reader.readLine();
}
catch (Exception e) {
println("bla"); // works well...
e.printStackTrace();
line = null;
}
if (line == null) {
// Stop reading because of an error or file is empty
noLoop();
}
else {
String[] pieces = split(line, TAB);
int x = int(pieces[0]);
int y = int(pieces[1]);
point(x, y);
}
}
}
1