Created
May 4, 2014 01:41
-
-
Save y-matsuwitter/11509327 to your computer and use it in GitHub Desktop.
どうしてもGoでTryCatchしたい人のためにtrycatch作った ref: http://qiita.com/y_matsuwitter/items/7f717833bc2af94bc6c7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go run trycatch.go | |
do something buggy | |
catch MyError | |
finally do something | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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