Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
v-k- opened this issue Jun 10, 2024 · 1 comment
Open

Comments

@v-k-
Copy link

v-k- commented Jun 10, 2024

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

@AlTimofeyev
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants