Skip to content

Instantly share code, notes, and snippets.

@y-matsuwitter
Created May 4, 2014 01:41
Show Gist options
  • Save y-matsuwitter/11509327 to your computer and use it in GitHub Desktop.
Save y-matsuwitter/11509327 to your computer and use it in GitHub Desktop.
どうしてもGoでTryCatchしたい人のためにtrycatch作った ref: http://qiita.com/y_matsuwitter/items/7f717833bc2af94bc6c7
$ go run trycatch.go
do something buggy
catch MyError
finally do something
done
package main
import "github.com/y-matsuwitter/trycatch"
type MyError struct {
error
}
func main() {
trycatch.TryCatch{}.Try(func() {
println("do something buggy")
panic(MyError{})
}).Catch(MyError{}, func(err error) {
println("catch MyError")
}).CatchAll(func(err error) {
println("catch error")
}).Finally(func() {
println("finally do something")
})
println("done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment