Files
dolt/d/try.go
Chris Masone df520db380 Use d.Try less granularly
We can still get useful error messages out of d.Try without
specifically wrapping every single thing that might throw a
noms UsageError, so do so. The code is cleaner.

Towards issue #176
2015-08-11 11:25:50 -07:00

26 lines
442 B
Go

package d
// Try calls f() and recovers from any panics caused by using d.Exp. The error generated by the call to d.Exp is returned.
func Try(f func()) (err error) {
defer nomsRecover(&err)
f()
return
}
type UsageError struct {
msg string
}
func (e UsageError) Error() string {
return e.msg
}
func nomsRecover(errp *error) {
if r := recover(); r != nil {
if _, ok := r.(UsageError); !ok {
panic(r)
}
*errp = r.(error)
}
}