https://github.com/fmorenovr/gotry
GoTry is a Try/Catch/Finally library implemented in golang.
https://github.com/fmorenovr/gotry
catch exception-handling exceptions finally go go-exception go-try golang google gotry try try-catch try-catch-finally
Last synced: 3 months ago
JSON representation
GoTry is a Try/Catch/Finally library implemented in golang.
- Host: GitHub
- URL: https://github.com/fmorenovr/gotry
- Owner: fmorenovr
- License: mit
- Created: 2018-04-14T20:34:04.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-08-19T17:40:23.000Z (over 6 years ago)
- Last Synced: 2024-06-20T22:33:36.886Z (almost 2 years ago)
- Topics: catch, exception-handling, exceptions, finally, go, go-exception, go-try, golang, google, gotry, try, try-catch, try-catch-finally
- Language: Go
- Homepage: https://godoc.org/github.com/fmorenovr/gotry
- Size: 5.86 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# golang + Try/Catch/Finally = GoTry
goTry (Golang for Try/Catch/Finally) is a Golang implementation for Exception handling.
You can see an extended doc in [godocs](https://godoc.org/github.com/fmorenovr/goTry).
## Try/Catch/Finally
This method is to Exception handling, in this case, when occurs a panic(), we can run a function instead that panic, maybe to solve that.
But is not recommendable to use this library, because golang have an explicit error handling.
See more info [here](https://golang.org/doc/effective_go.html).
## goTry
* First, You should download my library:
go get github.com/fmorenovr/gotry/
* Then, you should use for differents implements in Go.
gotry.Try(func() {
gotry.Throw("New exception")
}).Catch(func(e gotry.Exception) {
// Print crash
fmt.Println("Catch ---> exception catched #1:", e)
}).Finally(func() {
fmt.Println("Finally ---> This always print after all try block #1")
})
* Could be a nested Try/Catch block
gotry.Try(func() {
gotry.Throw("New exception")
}).Catch(func(e gotry.Exception) {
// Print crash
fmt.Println("Catch ---> exception catched #1:", e)
gotry.Try(func(){
gotry.Throw("New exception here!!")
}).Catch(func(e gotry.Exception) {
// Print crash
fmt.Println("Catch ---> exception catched #2:", e)
}).Finally(func() {
fmt.Println("Finally ---> This always print after all try block #2")
})
}).Finally(func() {
fmt.Println("Finally ---> This always print after all try block #1")
})