我有一个简单的脚本和只读数据库redis。
var redis = require('redis'),
client = redis.createClient(), multi
client.on('error', function(error) {
console.log('error')
})
tasks = []
tasks.push(['set', 'a', 1 ])
tasks.push(['set', 'b', 1 ])
client.multi(this.tasks).exec(function (err, replies) {
console.log(err)
tasks = []
tasks.push(['set', 'a', 1 ])
client.multi(tasks).exec(function (err, replies) {
console.log(err)
})
})
此脚本的结果:
null
null
/usr/local/lstat/lstat/node_modules/redis/index.js:468
throw callback_err;
^
Error: Error: Error: READONLY You can't write against a read only slave.
如何捕获此异常?
答案 0 :(得分:0)
语言node.js使用称为Javascript,在Javascript中捕获异常几乎是您所期望的:How to catch exceptions in javascript?