Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Try Catch #2

Open
Nicomedis opened this issue Nov 20, 2017 · 1 comment
Open

How to use Try Catch #2

Nicomedis opened this issue Nov 20, 2017 · 1 comment

Comments

@Nicomedis
Copy link

Interesting work. I am also playing around with this idea.
but i have problem when implement try catch on function with return value
i got error
cannot use func literal (type func() revel.Result) as type func(

I am using the try catch within a function that returns value like this, but still got the error:

func (c ToDo) Show(todo int) revel.Result { try.This(func() { panic("my panic") return c.RenderJSON("test") }).Catch(func(e try.E) { // Print crash return c.RenderJSON(e) }) }

is it done in wrong way?

@DENISDMITRIEVand
Copy link

package main

import (
"fmt"
"github.com/manucorporat/try"
)

func main() {
try.This(func() {
try.This(func() {
panic("my panic")

	}).Catch(func(e try.E) {
		fmt.Println("fixing stuff") // print
		try.Throw()                 // rethrow current exception!!
	})

}).Catch(func(e try.E) {
	// print
	fmt.Println(e)
})
fmt.Println("hey")

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants