I use mysql of node connection
//
addUser(userName, pwd) {
let connection = Mysql.createConnection({
host: MYSQL_CONFIG.HOST,
user: MYSQL_CONFIG.USER,
password: MYSQL_CONFIG.PASSWORD,
database: MYSQL_CONFIG.DATABASE
});
let sql = "INSERT INTO user(name, pwd) VALUES(?, ?)";
let sqlParams = [userName, pwd];
return new Promise((resolve) => {
connection.query(sql, sqlParams, function (err, result) {
if (err) {
resolve(": " + err.message);
connection.end();
}
resolve(``);
connection.end();
});
})
}
if the pwd exceeds the length limit of the pwd in the database, an exception will be thrown on the console
sometimes it means that the length of the field is exceeded, but I can"t find it.
both of these exceptions can cause program interruptions.
how can I change it to catch an exception so that the program will not be interrupted?