I am setting up a system that will query a MySQL database for registering and deleting staff and such. I was just wondering if there is a need to have the query in a try catch block or if it is simply redundant. I have an example below. My understanding is that this will throw an error but not crash the system as it will, as a try/catch does, catch the error and let the server remain functional.
var con = mysql.createConnection({
host: 'mysql1',
user: 'root',
database: 'assignment',
password: 'admin'
});
let sqlQuery = `INSERT INTO CBOdb (staffName, staffID, staffPassword, time) VALUES ('${staffName}', '${staffID}', '${staffPassword}', NOW())`;
try {
con.query(sqlQuery, function(err, result) {
if (err) {
throw err;
} else {
res.send(0)
}
})
} catch {
res.send(1) //"**Error ecounterd, staff not registerd**\nPlease contact system Administrator.")
}