Beispiel #1
0
func Test_CrashInThrow(T *testing.T) {
	calledFinally := false

	defer func() {
		err := recover()
		if err != "testing panic" {
			T.Error("error is not 'testing panic'")
		}
		// if finally was not called
		if !calledFinally {
			T.Error("Finally do not called")
		}
	}()

	try.This(func() {
		panic("testing panic")

	}).Finally(func() {
		calledFinally = true

	}).Catch(func(e try.E) {
		if e != "testing panic" {
			T.Error("error is not 'testing panic'")
		}
		try.Throw()

	})
}
Beispiel #2
0
func main() {
	try.This(func() {
		a := 10
		b := 0
		c := 0

		c = a / b
		fmt.Printf("result = %.2f\n", c)
	}).Finally(func() {
		fmt.Println("Done")
	}).Catch(func(_ try.E) {
		fmt.Println("exception catched")
		try.Throw() // rethrow current exception
	})
}
Beispiel #3
0
func Test_CrashInThrow2(T *testing.T) {
	defer func() {
		err := recover()
		if err != "testing panic" {
			T.Error("error is not 'testing panic'")
		}
	}()

	try.This(func() {
		panic("testing panic")

	}).Catch(func(e try.E) {
		if e != "testing panic" {
			T.Error("error is not 'testing panic'")
		}
		try.Throw()
	})
}