File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
go_basics/defer_panic_recover Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import "fmt"
4
+
5
+ // We will learn about defer, panic, recover
6
+
7
+ func calcSum [K int | float64 ](a K , b K ) K {
8
+ return a + b
9
+ }
10
+
11
+ func deferFuncExample () {
12
+ // defer stalls the execution of the instance linked to it
13
+ // defer runs after the corrosponding function block has finished running
14
+ // multiple defers use the LIFO algo, last defer goes out first
15
+ defer fmt .Println ("Something has been calculated" )
16
+ sum := calcSum (1 , 2 )
17
+ fmt .Println ("The sum is" , sum )
18
+
19
+ defer fmt .Println ("The sum of floats has been calculated" )
20
+
21
+ fmt .Println (calcSum (1.100 , 2.200 ))
22
+ }
23
+
24
+ func panicFuncExample () {
25
+
26
+ }
27
+
28
+ func main () {
29
+ deferFuncExample ()
30
+ }
Original file line number Diff line number Diff line change
1
+ module anarchymonkey.com/go-basics/defer-panic-recover
2
+
3
+ go 1.20
You can’t perform that action at this time.
0 commit comments