1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
package gohex
import (
"fmt"
)
type parseErrorType uint
const (
_SYNTAX_ERROR parseErrorType = 1
_RECORD_ERROR parseErrorType = 2
_DATA_ERROR parseErrorType = 3
_CHECKSUM_ERROR parseErrorType = 4
)
type parseError struct {
errorType parseErrorType
message string
lineNum uint
}
func (e *parseError) Error() string {
var str string = "error"
switch e.errorType {
case _SYNTAX_ERROR:
str = "syntax error"
case _RECORD_ERROR:
str = "record error"
case _DATA_ERROR:
str = "data error"
case _CHECKSUM_ERROR:
str = "checksum error"
}
return fmt.Sprintf("%s: %s at line %d", str, e.message, e.lineNum)
}
func newParseError(et parseErrorType, msg string, line uint) error {
return &parseError{errorType: et, message: msg, lineNum: line}
}
|