Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error interface {
Error() string
Stacktrace() Error
Trace(offset int, format string, args ...any) Error
Data() any
}
Usage with arbitrary error data:
```go
// Error construction
type MyError struct{}
var err1 error = NewWithData(MyError{}, "my message")
...
// Wrapping
var err2 error = Wrap(err1, "another message")
if (err1 != err2) { panic("should be the same")
...
// Error handling
switch err2.Data().(type){
case MyError: ...
default: ...
}
```
type FmtError ¶
type FmtError struct {
// contains filtered or unexported fields
}
FmtError is the data type for New() (e.g. New().Data().(FmtError)) Theoretically it could be used to switch on the format string.
```go
// Error construction
var err1 error = New("invalid username %v", "BOB")
var err2 error = New("another kind of error")
...
// Error handling
switch err1.Data().(cmn.FmtError).Format() {
case "invalid username %v": ...
case "another kind of error": ...
default: ...
}
```
Click to show internal directories.
Click to hide internal directories.