Hello mighty fighters of errors!

Here comes my half-thought idea of another way to express error handling:

*Add a postfix '?' that checks value for **emptiness (nil, 0, "") **AND an 
error for nil. *

(Denis have shred it to pieces already in 
https://github.com/golang/go/issues/32852. Thank you Denis.)

I am not good with expressing my inner talk, so there are couple examples

original , Go 1 function

func stat(filename string) (os.FileInfo, error) {

var info os.FileInfo
{
var a1 *os.File
if a1, err := os.Open(filename); err != nil || a1 == nil {
return _, err
}
var a2 os.FileInfo
if a2, err := a1.Stat(); err != nil || a2 == nil {
return _, err
}
info = a2
}
        return info, nil
}


And with "?", trying to avoid original try() proposal handle leak

// would return _, err, but since there is no err in signature, will return 
default value in case of error
// uses ? on func call that returns (value, error)
func stat2(filename string) (os.FileInfo) {
     file := os.Open(filename)? 
     defer file.Close()
     return file.Stat()?
}
// would return error too, uses ? as "not nil" on a variable too
func stat3(filename string) (_ os.FileInfo, err error) {
     var file *os.File
     defer file?.Close()
     file := os.Open(filename)?
     return file.Stat()
}


Thoughts?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b7520ffe-ec38-4157-8f95-92844dcb0d0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to