Hacker News new | ask | show | jobs
by ncmncm 2021 days ago
Every pre-, post-, and invariant condition violation represents a programming error, at an indeterminate point in the past, rendering the state of the computation unknown, and likely undefined, and definitely unrecoverable.

An exception, by definition, is to enable recovery from externally imposed events in a well-defined program state.

The only useful, meaningful response to discovering a contract violation is termination. Throwing an exception is the worst imaginable response.

1 comments

The exception throwing is a compromise, it allows you to view the stack trace in an IDE to find out which assertions failed.