32 lines
558 B
Go
32 lines
558 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type SMBError struct {
|
||
|
What string
|
||
|
When time.Time
|
||
|
}
|
||
|
|
||
|
// the receiver and that which is returned from generate_error must match
|
||
|
// types. You may change this to an SMBError pointer recevier, or change the
|
||
|
// return from generate_error to be an address.
|
||
|
func (e SMBError) Error() string {
|
||
|
return fmt.Sprintf("%v at %v", e.What, e.When)
|
||
|
}
|
||
|
|
||
|
func generate_error() error {
|
||
|
return SMBError{
|
||
|
"Here is a silly error",
|
||
|
time.Now(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
if err := generate_error(); err != nil {
|
||
|
fmt.Println(err)
|
||
|
}
|
||
|
}
|