processing4 icon indicating copy to clipboard operation
processing4 copied to clipboard

Reference for `Try` hangs the execution if there is no file to be loaded.

Open v-k- opened this issue 1 year ago • 1 comments

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

v-k- avatar Jun 10 '24 18:06 v-k-

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();  
}

AlTimofeyev avatar Jul 17 '24 08:07 AlTimofeyev