Skip to content

Instantly share code, notes, and snippets.

@iporsut
Last active August 29, 2015 14:16
Show Gist options
  • Save iporsut/faee0fe3880fa0ff36df to your computer and use it in GitHub Desktop.
Save iporsut/faee0fe3880fa0ff36df to your computer and use it in GitHub Desktop.
Div error
package main
import (
"errors"
"fmt"
)
func Div(a, b float32) (result float32, err error) {
if b == 0 {
err = errors.New("Cannot divide by zero.")
return
}
result = a / b
return
}
func main() {
if result, err := Div(5.0, 0); err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment