github.com/timandy/routine@v1.1.4-0.20240507073150-e4a3e1fe2ba5/api_error.go (about) 1 package routine 2 3 // RuntimeError runtime error with stack info. 4 type RuntimeError interface { 5 // Goid returns the goid of the coroutine that created the current error. 6 Goid() int64 7 8 // Gopc returns the pc of go statement that created the current error coroutine. 9 Gopc() uintptr 10 11 // Message returns the detail message string of this error. 12 Message() string 13 14 // StackTrace returns an array of stack trace elements, each representing one stack frame. 15 StackTrace() []uintptr 16 17 // Cause returns the cause of this error or nil if the cause is nonexistent or unknown. 18 Cause() RuntimeError 19 20 // Error returns a short description of this error. 21 Error() string 22 } 23 24 // NewRuntimeError create a new RuntimeError instance. 25 func NewRuntimeError(cause any) RuntimeError { 26 goid, gopc, msg, stackTrace, innerErr := runtimeErrorNew(cause) 27 return &runtimeError{goid: goid, gopc: gopc, message: msg, stackTrace: stackTrace, cause: innerErr} 28 } 29 30 // NewRuntimeErrorWithMessage create a new RuntimeError instance. 31 func NewRuntimeErrorWithMessage(message string) RuntimeError { 32 goid, gopc, msg, stackTrace, innerErr := runtimeErrorNewWithMessage(message) 33 return &runtimeError{goid: goid, gopc: gopc, message: msg, stackTrace: stackTrace, cause: innerErr} 34 } 35 36 // NewRuntimeErrorWithMessageCause create a new RuntimeError instance. 37 func NewRuntimeErrorWithMessageCause(message string, cause any) RuntimeError { 38 goid, gopc, msg, stackTrace, innerErr := runtimeErrorNewWithMessageCause(message, cause) 39 return &runtimeError{goid: goid, gopc: gopc, message: msg, stackTrace: stackTrace, cause: innerErr} 40 }