processing4
processing4 copied to clipboard
Reference for `Try` hangs the execution if there is no file to be loaded.
At https://processing.org/reference/try.html the code is only catching IOException, if there is no file, the NullPointer will hang the execution. This is not user wrong neither is very friendly for novices, not processingISH way of doing things, I dare say :)
It's not a website issue is it?
cheers
The reference could be amended to include a catch statement or an if statement to check for NullPointer. It's been a while since I've used Java but it should look something like this:
try {
line = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
line = null;
} catch (NullPointer n) {
line = null
}
Or something like this:
if (reader == NullPointer) {
// Don't read because file doesn't exist
noLoop();
}
try {
line = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
line = null;
}
if (line == null) {
// Stop reading because of an error or file is empty
noLoop();
}