/trunk/Examples/test-suite/go/exception_order_runme.go

# · Go · 58 lines · 51 code · 7 blank · 0 comment · 15 complexity · 8744dc085a5078cd403670d7175a0f93 MD5 · raw file

  1. package main
  2. import "strings"
  3. import . "./exception_order"
  4. func main() {
  5. a := NewA()
  6. func() {
  7. defer func() {
  8. e := recover()
  9. if strings.Index(e.(string), "E1") == -1 {
  10. panic(e.(string))
  11. }
  12. }()
  13. a.Foo()
  14. }()
  15. func() {
  16. defer func() {
  17. e := recover()
  18. if strings.Index(e.(string), "E2") == -1 {
  19. panic(e.(string))
  20. }
  21. }()
  22. a.Bar()
  23. }()
  24. func() {
  25. defer func() {
  26. e := recover()
  27. if e.(string) != "postcatch unknown" {
  28. panic("bad exception order")
  29. }
  30. }()
  31. a.Foobar()
  32. }()
  33. func() {
  34. defer func() {
  35. e := recover()
  36. if strings.Index(e.(string), "E1") == -1 {
  37. panic(e.(string))
  38. }
  39. }()
  40. a.Barfoo(1)
  41. }()
  42. func() {
  43. defer func() {
  44. e := recover()
  45. if strings.Index(e.(string), "E2") == -1 {
  46. panic(e.(string))
  47. }
  48. }()
  49. a.Barfoo(2)
  50. }()
  51. }