visionmedia/express — Issue #949: fn argument to res.render is unclear
Author: reaktivo
Created: 2012-01-04 01:14:38+00:00
State: open

The other day I was trying to catch the view location failure error in a try/catch block without any success like the following

````javascript
app.get("/page/:id", function(req, res) {
// if view with name == req.params.id
// doesn't exist just render index
try{
res.render(req.params.id);
catch(error){
res.render("index");
}
});
````

but after digging around, found out res.render only throws the error when a fifth argument (sub) is sent, which is not really clear what this is for. I found out I can do this like so

````javascript
app.get("/page/:id", function(req, res) {
res.render(req.params.id, function() {
res.render("index");
});
});
````

I'm just not sure the function argument is meant for this, because the docs say the following:
> When a callback function is given a response will not be made automatically