The language specification seems silent on what is returned from a defer'd function. The current implementation appears to just return nil, making it difficult to determine the true outcome of the defer'd function.
Is this correct?
Will defer'd functions always return nil? That is, is there any thought to allowing defer to return real values in later versions of Go?
Meanwhile, is there any alternative to handling this case other than isolating panics from opens in separate functions?
func handleWork() {
...
data, err := doWork()
if err != nil { handleProblem(data); }
if data == nil { return; }
processData(data)
...
}
func doWork() ([]byte, error) {
defer func() ([]byte, error) {
if err := recover(); err != nil {
return myDefault, myError // should not return nil, nil
}
return closeResources() // can validly return nil, nil
}
...
openResources()
...
panicingFunction()
}