Skip to content

Commit 21af113

Browse files
committed
Ders 25
1 parent d9208a6 commit 21af113

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

25_error_handling/main.go

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* package main
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
)
7+
8+
func main() {
9+
10+
result, err := evenNum(11)
11+
if err != nil {
12+
fmt.Println(err)
13+
} else {
14+
fmt.Println("Girdiğiniz sayı: ", result)
15+
}
16+
17+
}
18+
19+
func evenNum(num int) (int, error) {
20+
if num%2 != 0 {
21+
return 0, errors.New("HATA: Çift sayı girmediniz")
22+
}
23+
24+
return num, nil
25+
} */
26+
27+
/* package main
28+
29+
import (
30+
"errors"
31+
"fmt"
32+
"math"
33+
)
34+
35+
func main() {
36+
37+
result, err := sRoot(-5)
38+
if err != nil {
39+
fmt.Println(err)
40+
} else {
41+
fmt.Println(result)
42+
}
43+
}
44+
45+
func sRoot(num float64) (float64, error) {
46+
if num < 0 {
47+
return 0, errors.New("Negatif sayıların karekökü alınamaz")
48+
}
49+
50+
return math.Sqrt(num), nil
51+
} */
52+
53+
/* package main
54+
55+
import (
56+
"fmt"
57+
"math"
58+
)
59+
60+
func main() {
61+
62+
result := sRoot(-4)
63+
{
64+
fmt.Println(result)
65+
}
66+
}
67+
68+
func sRoot(num float64) float64 {
69+
70+
return math.Sqrt(num)
71+
} */
72+
73+
package main
74+
75+
import (
76+
"fmt"
77+
"os"
78+
)
79+
80+
func main() {
81+
82+
file, err := os.Open("test.txt")
83+
if err != nil {
84+
fmt.Println(err)
85+
} else {
86+
fmt.Println("Dosyamız", file)
87+
}
88+
89+
}

25_error_handling/test.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)