github.com/haraldrudell/parl@v0.4.176/perrors/is-panic.go (about)

     1  /*
     2  © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package perrors
     7  
     8  import (
     9  	"github.com/haraldrudell/parl/perrors/errorglue"
    10  	"github.com/haraldrudell/parl/pruntime"
    11  )
    12  
    13  // IsPanic determines if err is the result of a panic. Thread-safe
    14  //   - isPanic is true if a panic was detected in the inner-most stack trace of err’s error chain
    15  //   - err must have stack trace from [perrors.ErrorfPF] [perrors.Stackn] or similar function
    16  //   - stack[recoveryIndex] is the code line of the deferred function containing recovery invocation
    17  //   - stack[panicIndex] is the code line causing the panic
    18  //   - [perrors.Short] displays the error message along with the code location raising panic
    19  //   - [perrors.Long] displays all available information about the error
    20  func IsPanic(err error) (isPanic bool, stack pruntime.Stack, recoveryIndex, panicIndex int) {
    21  	isPanic, stack, recoveryIndex, panicIndex, _, _ = errorglue.FirstPanicStack(err)
    22  	return
    23  }