Created
May 24, 2020 08:02
-
-
Save LuoZijun/2f656d17bcb76f3dccdaa26d5124c6f2 to your computer and use it in GitHub Desktop.
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 "fmt" | |
import "math/big" | |
type BigInt big.Int | |
func one() *big.Int { | |
return big.NewInt(1) | |
} | |
func zero() *big.Int { | |
return big.NewInt(0) | |
} | |
func add(a *big.Int, b *big.Int) *big.Int { | |
return zero().Add(a, b) | |
} | |
func Transaction(handle func() interface {}) interface {} { | |
defer func() { | |
if r := recover(); r != nil { | |
fmt.Println("Recovered in f", r); | |
} | |
}() | |
return handle(); | |
} | |
func main() { | |
var a *big.Int; | |
var b *big.Int; | |
Transaction(func() interface {} { | |
// NOTE: 这里会 Panic,但是线程不会崩溃 | |
c := add(a, b); | |
fmt.Println("%s", c.String()); | |
return nil; | |
}); | |
// NOTE: 整个线程不会崩溃。 | |
fmt.Println("DONE."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment