github.com/sandwich-go/boost@v1.3.29/xpanic/README.md (about)

     1  # xpanic
     2  
     3  `panic` 辅助函数
     4  
     5  - `error` 不为 `nil` 时, `panic`
     6  - `true` 时,`panic`
     7  - `try cache panic`
     8  
     9  # 例子
    10  ```go
    11  Do(func() {
    12      fmt.Println("Doing something...")
    13      panic("Something wrong happened!")
    14  }, func(p *Panic) {
    15      fmt.Println("Caught a panic:", p.Reason)
    16  })
    17  
    18  AutoRecover("something", func(){
    19      // do something
    20      // if panic, auto execute this function continue.
    21  })
    22  
    23  Try(func() {
    24      WhenErrorAsFmtFirst(err, "%w, %d", 1)
    25  }).Catch(func(err E) {
    26      fmt.Println(err)
    27  })
    28  ```
    29  Output:
    30  ```text
    31  error, 1
    32  ```