Node.js UDP processing error (dgram) from DNS resolution

I am making a simple UDP “send” using Node's built-in UDP socket datagram:

http://nodejs.org/docs/v0.3.1/api/dgram.html

The purpose of the message is the domain name that must be resolved by DNS before the transfer .. node.js handles this.

If the DNS resolution fails, dgram generates an "ENOTFOUND Domain Not Found" error and passes it to the callback that I registered.

My code looks like this:

client = dgram.createSocket("udp4");
client.send(message, 
            0, 
                message.length, 
                this.port, 
                this.address, 
                function(err, bytes) { 
                    if (err) { 
                        //get rid of error??
                        } 
                    }
                );
client.close();

I'm not particularly interested in the error. If it fails, it fails, which is not important for the business rules of the application. I will write it to the console for completeness. BUT I cannot stop this exception by going back to the stack and knocking the application down. How can I handle this error?

, . Try/Except.. .

?

.

+3
1

error . , node . uncaughtException, , uncaughtException, - , .

error DNS:

var dgram = require('dgram');
var message = new Buffer("Some bytes");
var client = dgram.createSocket("udp4");
client.on("error", function (err) {
    console.log("Socket error: " + err);
});
client.send(message, 0, message.length, 41234, "1.2.3.4.5");

:

Socket error: Error: ENOTFOUND, Domain name not found

.

+1

All Articles