Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
423 B

  1. package main
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. func main() {
  7. a()
  8. fmt.Println("This line will now get printed from main() function")
  9. }
  10. func a() {
  11. b("good-bye")
  12. fmt.Println("Back in function a()")
  13. }
  14. func b(msg string) {
  15. defer func() {
  16. if r := recover(); r != nil {
  17. fmt.Println("error in func b()", r)
  18. }
  19. }()
  20. if msg == "good-bye" {
  21. panic(errors.New("something went wrong"))
  22. }
  23. fmt.Print(msg)
  24. }