feat(Go-StudyExample):包方法重构

This commit is contained in:
Huangzj
2020-12-16 11:30:31 +08:00
parent 1d21a9634e
commit a97c2c9bcc
17 changed files with 74 additions and 125 deletions
+38
View File
@@ -0,0 +1,38 @@
/*
* @Author : huangzj
* @Time : 2020/7/13 14:24
* @Descriptiongo运行时错误测试
*/
package originGoLanguage
import (
"errors"
"fmt"
"testing"
)
func TestError(t *testing.T) {
fmt.Println("测试创建一个新的错误")
testNewError()
fmt.Println("")
}
func testNewError() {
var fl1 float32 = 0
fl2, err := tError(fl1)
fmt.Println(fl2, err)
var flx float32 = 2.2
fl3, err1 := tError(flx)
fmt.Println(fl3, err1)
}
func tError(f float32) (float32, error) {
if f == 0 {
return 0, errors.New("错误")
}
return f, nil
}