gorhill / cronexpr

Cron expression parser in Go language (golang)
687 stars 169 forks source link

Why using panic? #8

Closed h4ckm03d closed 10 years ago

h4ckm03d commented 10 years ago

Why using panic instead of return error? because it will break all application if MustParse function got error.

func MustParse(cronLine string) *Expression {
    expr, err := Parse(cronLine)
    if err != nil {
        panic(err)
    }
    return expr
}

CMIIW, I prefer like this.

func MustParse(cronLine string) (*Expression, error) {
    expr, err := Parse(cronLine)
    if err != nil {
        return nil, err 
    }
    return expr,nil
}
gorhill commented 10 years ago

Use func Parse(cronLine string) (*Expression, error) if you prefer this form.