github.com/haraldrudell/parl@v0.4.176/recover-err.go (about)

     1  /*
     2  © 2023–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package parl
     7  
     8  // RecoverErr recovers panic using deferred annotation
     9  //   - signature is error pointer and a possible isPanic pointer
    10  //
    11  // Usage:
    12  //
    13  //	func someFunc() (isPanic bool, err error) {
    14  //	  defer parl.RecoverErr(func() parl.DA { return parl.A() }, &err, &isPanic)
    15  func RecoverErr(deferredLocation func() DA, errp *error, isPanic ...*bool) {
    16  	var isPanicp *bool
    17  	if len(isPanic) > 0 {
    18  		isPanicp = isPanic[0]
    19  	}
    20  	doRecovery(noAnnotation, deferredLocation, errp, NoOnError, recoverOnErrrorNone, isPanicp, recover())
    21  }