Add panic

This commit is contained in:
Sangeeth Sudheer 2024-05-01 18:39:16 +05:30
parent b2314b5f63
commit 36574bafdf
Signed by: x
GPG Key ID: F6D06ECE734C57D1
2 changed files with 21 additions and 2 deletions

View File

@ -18,7 +18,8 @@ package main
// import "git.sangeeth.dev/gobyexample/atomics" // import "git.sangeeth.dev/gobyexample/atomics"
// import "git.sangeeth.dev/gobyexample/mutex" // import "git.sangeeth.dev/gobyexample/mutex"
// import "git.sangeeth.dev/gobyexample/statefulgoroutines" // import "git.sangeeth.dev/gobyexample/statefulgoroutines"
import "git.sangeeth.dev/gobyexample/sorting" // import "git.sangeeth.dev/gobyexample/sorting"
import "git.sangeeth.dev/gobyexample/panic"
func main() { func main() {
// runes.Runes() // runes.Runes()
@ -39,5 +40,6 @@ func main() {
// atomics.Atomics() // atomics.Atomics()
// mutex.Mutex() // mutex.Mutex()
// statefulgoroutines.StatefulGoroutines() // statefulgoroutines.StatefulGoroutines()
sorting.Sorting() // sorting.Sorting()
panic.Panic()
} }

17
panic/panic.go Normal file
View File

@ -0,0 +1,17 @@
package panic
import (
"fmt"
"os"
)
func Panic() {
p := "/cantcreate.txt"
_, err := os.Open(p)
if err != nil {
panic(fmt.Errorf("omg error when creating file %w", err))
}
fmt.Printf("%s created somehow!\n", p)
}