Debian Codegraph @

test/typeparam/issue45722.go

raw
1 // run
2
3 // Copyright 2021 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package main
8
9 import (
10 "fmt"
11 "log"
12 )
13
14 func try[T any](v T, err error) T {
15 if err != nil {
16 panic(err)
17 }
18 return v
19 }
20
21 func 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
31 func main() {
32 defer handle(func(e error) { log.Fatalln(e) })
33 _ = try(fmt.Print(""))
34 }