1package ole 2 3// OleError stores COM errors. 4type OleError struct { 5 hr uintptr 6 description string 7 subError error 8} 9 10// NewError creates new error with HResult. 11func NewError(hr uintptr) *OleError { 12 return &OleError{hr: hr} 13} 14 15// NewErrorWithDescription creates new COM error with HResult and description. 16func NewErrorWithDescription(hr uintptr, description string) *OleError { 17 return &OleError{hr: hr, description: description} 18} 19 20// NewErrorWithSubError creates new COM error with parent error. 21func NewErrorWithSubError(hr uintptr, description string, err error) *OleError { 22 return &OleError{hr: hr, description: description, subError: err} 23} 24 25// Code is the HResult. 26func (v *OleError) Code() uintptr { 27 return uintptr(v.hr) 28} 29 30// String description, either manually set or format message with error code. 31func (v *OleError) String() string { 32 if v.description != "" { 33 return errstr(int(v.hr)) + " (" + v.description + ")" 34 } 35 return errstr(int(v.hr)) 36} 37 38// Error implements error interface. 39func (v *OleError) Error() string { 40 return v.String() 41} 42 43// Description retrieves error summary, if there is one. 44func (v *OleError) Description() string { 45 return v.description 46} 47 48// SubError returns parent error, if there is one. 49func (v *OleError) SubError() error { 50 return v.subError 51} 52