Skip to content

Instantly share code, notes, and snippets.

@willis7
Last active January 3, 2017 20:26
Show Gist options
  • Save willis7/0ed2da40ccdd91b6dfbcb4a8241f793e to your computer and use it in GitHub Desktop.
Save willis7/0ed2da40ccdd91b6dfbcb4a8241f793e to your computer and use it in GitHub Desktop.
An example, the json package specifies a SyntaxError type that the json.Decode function returns when it encounters a syntax error parsing a JSON blob.
if err := dec.Decode(&val); err != nil {
if serr, ok := err.(*json.SyntaxError); ok {
line, col := findLine(f, serr.Offset)
return fmt.Errorf("%s:%d:%d: %v", f.Name(), line, col, err)
}
return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment