私は次のようなコードを持っています:
app.js
app.use(app.router)
app.use(function(err, req, res, next) {
res.render(errorPage)
})
app.get('/', function(req,res,next) {
module1.throwException(function{ ... });
});
module1.js
exports.thowException = function(callback) {
// this throws a TypeError exception.
// follwoing two lines are getting executed async
// for simplicity I removed the async code
var myVar = undefined;
myVar['a'] = 'b'
callback()
}
module1.js の例外を除いて、私のノード prcoess は停止します。代わりに、エラーページをレンダリングしたかったのです。
app.get(..) で try ... catch を試してみましたが、役に立ちませんでした。
これどうやってするの??