Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "log"
- )
- func main() {
- defer func() {
- if err := recover(); err != nil {
- log.Println("panic arrived in main:", err)
- }
- }()
- divideByZero()
- fmt.Println("we survived dividing by zero!")
- }
- func divideByZero() {
- defer func() {
- if err := recover(); err != nil {
- log.Println("panic occurred:", err)
- }
- }()
- fmt.Println(divide(1, 0))
- }
- func divide(a, b int) int {
- return a / b
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement