GO by example, part 5
This commit is contained in:
16
5-go-by-example/43-panic.go
Normal file
16
5-go-by-example/43-panic.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import "os"
|
||||
|
||||
// a panic typically means something went unexpectedly wrong
|
||||
func main() {
|
||||
|
||||
// this is the only code here designed to panic
|
||||
panic("a problem")
|
||||
|
||||
// a common use of panic is to abort if a function returns an error value that one doesn’t know how to handle
|
||||
_, err := os.Create("/tmp/file")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user