Skip to content

Instantly share code, notes, and snippets.

@LuoZijun
Created May 24, 2020 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuoZijun/2f656d17bcb76f3dccdaa26d5124c6f2 to your computer and use it in GitHub Desktop.
Save LuoZijun/2f656d17bcb76f3dccdaa26d5124c6f2 to your computer and use it in GitHub Desktop.
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