Last active
August 29, 2015 14:16
-
-
Save iporsut/faee0fe3880fa0ff36df to your computer and use it in GitHub Desktop.
Div error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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