exercism/go/error-handling/error_handling.go
2017-08-15 09:55:28 -05:00

36 lines
518 B
Go

package erratum
const testVersion = 2
func Use(o ResourceOpener, inp string) (err error) {
var r Resource
moveOn := false
for !moveOn {
moveOn = true
if r, err = o(); err != nil {
switch err.(type) {
case TransientError:
moveOn = false
default:
return err
}
}
}
defer r.Close()
defer func() {
if rec := recover(); rec != nil {
switch v := rec.(type) {
case FrobError:
r.Defrob(v.defrobTag)
err = v
case error:
err = v
}
}
}()
r.Frob(inp)
return err
}