Re:The Go Programming Language, or: Why all C-like languages...
by ericbb on Thursday March 08, 2012 @09:47PM
(#3682679)
The error type is an interface. You can return values that contain contextual information as long as the error value you return has an Error() method returning a string.
Note: The current release may vary slightly on the details. I'm using a pre-release build. But older versions are similar.
[ Parent
| on HN ]
Re:The Go Programming Language, or: Why all C-like languages...
by casualsuperman2 on Friday March 09, 2012 @06:23PM
(#3686427)
And then in the code for handling the error, you can do
switch err.(type) {
case db.IOError:
// Database exception here
case io.FileNotFoundError:
// File exception
default:
// Pass it to our caller for them to handle.
return nil, err
}
Which gives you the ability to selectively catch errors based on type.