3 ms·
Well, panic should mostly be happening as a result of nil pointer deref, slice out of bounds, etc. You wouldn't want those types of operations to return error v
by echlebek 8y ago
Well, panic should mostly be happening as a result of nil pointer deref, slice out of bounds, etc. You wouldn't want those types of operations to return error values.
- d0100 8y agoBut for those you can do a manual bounds & pointer check.
- skj 8y agoYour code is allowed to panic if there is a bug. For instance, the caller passed in a nil pointer where there needed to be actual data. Errors are for when the input (specifically the I/O) is wrong, a precondition isn't met, or some other error that doesn't mean there is something fundamentally wrong with your code. If to make the problem go away you need to fix the code, panic is OK.