Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. func (foo *Foo) Bar() (err error) {
  2.  
  3. foo.Begin()
  4. defer foo.End()
  5.  
  6. //some business code
  7. err = fmt.Errorf("oh no, an error!") // set error so that Bar returns it even though it's caught
  8. panic(err)
  9.  
  10. return
  11. }
  12.  
  13. func (foo *Foo) End() {
  14. err := recover()
  15. if err != nil {
  16. foo.Rollback()
  17. } else {
  18. foo.Commit()
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement