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.

28 lines
411 B

  1. package main
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. func main() {
  7. test()
  8. fmt.Println("This line will not get printed")
  9. }
  10. func test() {
  11. n := func() {
  12. fmt.Println("Defer in test")
  13. }
  14. defer n()
  15. msg := "good-bye"
  16. message(msg)
  17. }
  18. func message(msg string) {
  19. f := func() {
  20. fmt.Println("Defer in message func")
  21. }
  22. defer f()
  23. if msg == "good-bye" {
  24. panic(errors.New("something went wrong"))
  25. }
  26. }