In every documentation, I read something like that for sentinel errors:
Sentinel errors are usually used to indicate that you cannot start or proceed.
That could also be the case for any possible error, isn't it? Because anything unexpected can happen in Runtime. Does it mean errors that I expect in Runtime but can or should handle better, do I call sentinel errors?
Then I read how they should be used:
Sentinel errors are among the few variables declared at the package level. Their names start with
Err
(Exceptionio.EOF
). They should be threatened as read-only. (Go compiler cannot enforce this).
Before you define a sentinel error, make sure you need one. Once defined, it becomes part of your public API, and you have committed to making it available in all future backwards-compatible releases.
Or does the way I handle them make them sentinel errors? Could you give me an example to understand clearly, what the difference is?
Would it be wrong to say: Errors, I want to stand sentinel over in Runtime, and I explicitly define in my package root as variables (or constants) are sentinel errors?
I've prepared an example; maybe we can use it as a basis: https://go.dev/play/p/qwi4ligYZYh
io.EOF
error value is a perfect example, say you have a file-reading process and you expect that process to eventually reach the end of the file, so you have that process check forio.EOF
but, once encountered, you do not consider it an error, instead you simply terminate that process. Or, say, the process encountersio.EOF
right at the beginning, without being able to read a single byte, then you may opt to return theio.EOF
error to the caller to indicate that empty files are not valid arguments. – Adhesivego/build.NoGoError
, andpath/filepath.SkipDir
frompath/filepath.Walk
. These are the things that a beginner cannot know. So I would like a little more patience from you. After all, I want to learn and I also pass on my knowledge, as soon as I can do something, I help the people who can't. A little more patience, a little more kindness wouldn't hurt anyone. – Diastrophism