Error handling clarification
Mark-81 opened this issue · 2 comments
Following the examples here a snippet of my code:
process.on('uncaughtException', err => {
console.error((new Date).toUTCString() + ' uncaughtException:', err);
console.error("Exiting...");
process.exit(1)
})
// ...
var DB = require('node-adodb'), connection = DB.open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=pathToDatabase.mdb');
function submit(data, callback) {
var id = data.id;
var query = // create query from data values
connection
.execute(query)
.then(data => {
return callback({ id: id, success: true });
})
.catch(error => {
console.error('submit query failed: ' + error.process.message);
return callback({ id: id, success: false });
});
}
So I'm expecting that if the query fails it nicely calls the callback reporting the failure.
To test it, after initialization I suddenly remove the database file. The error is apparently handled:
submit query failed: Impossibile trovare il file pathToDatabase.mdb
but then the program crashes due to an "unhandled error":
Tue, 15 Jan 2019 12:33:23 GMT uncaughtException: { Error: Unhandled "error" event. ([object Object])
Exiting...
I'm running Node v8.12.0 under Windows 7.
I forgot something in the configuration/use of node-adodb
?
Some exception throw by cscript
, but cscript
exception information is bad!
[I don't think is so nice to immediately close an issue without waiting for a while if users have any further question...]
Anyway, I kindly ask an example how to handle such a situation. I understand cscript
exception information is bad, but I cannot let my program crash. Would you mind to show m how to change my snippet above in order to correctly catch the exception? Thanks in advance.