Node.js http with mysql pooling quits unexpectedly on error

So I started to try node.js this morning and was able to come-up with a http service that handles path requests and can connect to mysql with pooling for multiple transactions.

I am just having problems if ever I tried to make the password wrong, etc the node process quits unexpectedly.

var http = require("http");
var url = require("url");
var mysql = require('mysql');
var pool = mysql.createPool({
    host : 'localhost',
    user : 'root',
    password : 'root',
    database : 'test'
});

...

var pathname = url.parse(request.url).pathname;
var url_parts = url.parse(request.url, true);
var query = url_parts.query;

...

var table = query.table;
var sql = "SELECT * FROM " + table + "";

...

pool.getConnection(function(err, connection) {
        console.log(err);
        connection.on('error', function(err) {
            console.log(err.code);
        });

        // Use the connection
        connection.query(sql, function(err, rows) {
        if (err) throw err;
        console.log(rows);

        response.writeHead(200, {
            "Content-Type" : "application/json"
        });

        response.write(JSON.stringify(rows, null, 0));

        connection.end();
        response.end();
    });

    console.log(connection.sql);
    console.log(connection.query);
});

Appreciate any help on how can I make it not to QUIT! and just say the damn error.

Anyway, I used forever to make this node.js to never quit on me, in-cases of error.

You use throw err, but don t catch it anywhere, causing node a UncaughtException Error, closing the app.