gorilla/mux — pull request #58 by AlekSi (2014-05-29 14:54:32+00:00)
Title: Add panic handler.

Hello. This pull request adds basic ability to handle panics in handlers:

```go
type panicHandler struct{}

func (*panicHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
p := recover()
if p != nil {
rw.WriteHeader(500)
log.Print(p)
// something else
}
}

func main() {
r := mux.NewRouter()
r.PanicHandler = new(panicHandler)
}
```

I think that this style of panic handling is as useful as 404 handler, and definitely is an improvement over default `http` package behavior.

The obvious gotcha with this approach that one can't use function and `HandlerFunc` instead of type implementing `http. Handler` for not-so-obvious reason.

Another approach is to define custom type like:
```go
type PanicHandler interface {
ServeHTTP(rw ResponseWriter, req *Request, p interface{})
}
```

I'm open for discussion.