Error Custom example
This commit is contained in:
parent
543286da57
commit
0418380fd2
2 changed files with 22 additions and 0 deletions
21
error_handling/demo3.go
Normal file
21
error_handling/demo3.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package error_handling
|
||||
|
||||
import "fmt"
|
||||
|
||||
type borderException struct{
|
||||
parameter int
|
||||
message string
|
||||
}
|
||||
|
||||
func (b *borderException) Error() string{
|
||||
return fmt.Sprintf("%d ---- %s", b.parameter, b.message)
|
||||
}
|
||||
|
||||
func GuessIt2(guess int) (string, error){
|
||||
if guess < 1 || guess > 100{
|
||||
return "", &borderException{guess, "Out of border"}
|
||||
}
|
||||
|
||||
return "You did it", nil
|
||||
}
|
||||
|
1
main.go
1
main.go
|
@ -124,4 +124,5 @@ func main() {
|
|||
error_handling.Demo1()
|
||||
interfaces.Demo3()
|
||||
error_handling.Demo2()
|
||||
fmt.Println(error_handling.GuessIt2(102))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue