Skip to content

chrismwendt/go-exceptions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-exceptions

Ergonomic error handling in Go. Check out this post for more details.

Example

Typical error-handling:

func f() error {
  err := g1()
  if err != nil {
    return err
  }

  v1, err := g2()
  if err != nil {
    return err
  }

  // ...
}

With go-exceptions:

import ex "github.com/chrismwendt/go-exceptions"

func f() (err error) {
  defer ex.Catch(&err)        // Catch() calls recover() and assigns the error to &err

  ex.Throw(g1())              // Throw() calls panic() if the error argument is not nil
  v1 := ex.Throw1(g2())       // Throw{1,2}() also return values
  v2 := ex.Throw1(g3(), "g3") // Throw() also accepts a label
  // ...
}

About

Ergonomic error-handling in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages