codekingpro/portable-devtools
114k
1// run2 3// Copyright 2021 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.6 7package main8 9import (10 "fmt"11 "log"12)13 14func try[T any](v T, err error) T {15 if err != nil {16 panic(err)17 }18 return v19}20 21func handle(handle func(error)) {22 if issue := recover(); issue != nil {23 if e, ok := issue.(error); ok && e != nil {24 handle(e)25 } else {26 handle(fmt.Errorf("%v", e))27 }28 }29}30 31func main() {32 defer handle(func(e error) { log.Fatalln(e) })33 _ = try(fmt.Print(""))34}35 