===============同步捕获,
var http = require('http');
var fs = require('fs');
var url = require('url');
var routes=require('./models/routes');
http.createServer(function (request, response) {
var pathname = url.parse(request.url).pathname;
if(pathname!="/favicon.ico"){
pathname=pathname.replace(/\//,"");// 吧/去掉
try{//入股错误就不执行了
routes[pathname](request,response);//根据路径分发路由,执行相应的程序
}catch(err){
console.log("错误"+err);
response.writeHead(200,{"Content-Type":"text/html"});
response.write(err.toString());
response.end("");
}
console.log("主程序执行完毕");
}
}).listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
=======================异步捕获,
如果有异步的的错误(异步的err在每一个回调方法都有),则主程序的err就不会执行;
如果throw 异常后,后面的代码就不执行了;