I have this code

var fd = fs.openSync(filePath,"r");
var fr = fs.readSync(fd, buffer, 0, size, 0);

and it throws error like that

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: OK, open 'C:\Users\iahmed16\Desktop\eclipse WS\test\images\af31a9e0a98939be82f887b0005c21752e71425e.jpg'
  • how to handle this error ??
  • what's the meaning of the error if you know ??
有帮助吗?

解决方案

The error seems to mean that you have too many file descriptions open.

You have to make sure at some point that you close() them.

var fd = fs.openSync(filePath,"r");
var fr = fs.readSync(fd, buffer, 0, size, 0);
fs.closeSync(fd);

As for how to handle the error, you can use try...catch with thrown errors:

try {
    var fd = fs.openSync(filePath,"r");
    var fr = fs.readSync(fd, buffer, 0, size, 0);
    fs.closeSync(fd);
} catch (e) {
    console.log('Error:', e);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top