errors
Node.js
const err1 = new Error('some error')
console.log(err1)
class FooError extends Error{
constructor(message) {
super(message)
this.name = 'FooError'
this.message = message
}
toString() {
return this.message
}
}
const err2 = new FooError('my custom error')
console.log(err2)
Output
Error: some error
{ FooError: my custom error }
Go
package main
import (
"errors"
"fmt"
)
type FooError struct {
s string
}
func (f *FooError) Error() string {
return f.s
}
func NewFooError(s string) error {
return &FooError{s}
}
func main() {
err1 := errors.New("some error")
fmt.Println(err1)
err2 := NewFooError("my custom error")
fmt.Println(err2)
}
Output
some error
my custom error
当前内容版权归 miguelmota 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 miguelmota .