I have a web-page served by node.js. In the web-page is a loadTable which loads a csv file from disk. loadTable is async and the draw action is controlled by iLoadData. In the good callback, this is incremented and the next phase uses the data in the table. This all works fine. When the the file is missing it goes into the ‘bad’ callback, but then crashes. The bad callback sets iLoadData to zero and there’s no more action in draw, but it still crashes. How should I handle this error?
Partial code:
function loadTableGood()
{
console.log("T Good");
iLoadData++;
}
function loadTableBad()
{
console.log("T Bad " + iLoadData);
iLoadData = 0;
}
void draw()
{
...
if (iLoadData == 2)
{
table = loadTable(sFilename, 'csv', "", loadTableGood, loadTableBad);
}
if (iLoadData == 3)
{
// read out of the table.
}
...
}
[sketch.js:573:11](http://192.168.1.14:8083/sketch.js)
T Bad 2 [sketch.js:408:10](http://192.168.1.14:8083/sketch.js)
Uncaught (in promise) Error: [object Object]
n http://192.168.1.14:8083/p5.min.js:3
promise callback*[46]</v.prototype.httpDo http://192.168.1.14:8083/p5.min.js:3
loadTable http://192.168.1.14:8083/p5.min.js:3
draw http://192.168.1.14:8083/sketch.js:506
Uncaught (in promise) Error: [object ReadableStream] at p5:3:607922
However it doesn’t crash the sketch, as it goes on loading the correct filename “xy.csv” after that 1st fail and the sketch’s canvas keeps on changing its background() color.
the problem with the phases in the code wasn’t quite the same as I posted. (At the time I couldn’t think how to extract a minimum working example from my sprawling development.) There was a problem with testing iLoadData and I was sometimes reading the table before it was ready. I thought the ‘uncaught’ was the problem but it has to be ignored.
Your example is interesting, several new-to-me useful things:
Uint8Array.from - array construction.
use strict - (= ‘option explicit’ in VB 20 years ago)