0

I have a simple script and read-only database 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)
   })
})

Result of this script:

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.

How to catch this exception ?

Bdfy
  • 23,141
  • 55
  • 131
  • 179
  • 1
    possible duplicate of [Node.js Best Practice Exception Handling](http://stackoverflow.com/q/7310521/10293) – Robert Harvey Jul 02 '12 at 15:46
  • If you shorten the example script it is useful to also use a corresponding error output. I can't find line 468 in your example script ;-) – TheHippo Jul 02 '12 at 22:27

1 Answers1

0

The language node.js uses is called Javascript and catching exceptions in Javascript is pretty much what you would expect it to be: How to catch exceptions in javascript?

Community
  • 1
  • 1
Timothy Strimple
  • 22,920
  • 6
  • 69
  • 76