What is the difference between Exception and Error?

Most of the classes that inherit Exception end with Error, and a few end with Exception, what is the naming rule?

Related: Standardize naming and documentation of Exceptions and Errors · Issue #5559 · crystal-lang/crystal · GitHub

1 Like

I found a history of heated discussions about Exception, but there doesn’t seem to be agreement.

In most cases it should be error.

What is an “exception” anyway?

A common argument in issues and forums is that not all exceptions are errors, and not all errors are exceptions. However, that in itself is confusing because it provides no information as to what denotes an error or an exception. A common argument I’ve seen for this is interrupting the current flow of a process (which is basically the definition of exception) for example, KeyboardInterrupt in Python or SystemExit in Ruby. This makes sense for languages like those, but not so much for Crystal, and isn’t even used in the standard library or compiler; everything has it’s own way of handling errors.

Furthermore, a common practice seen in a lot of shards (and even in the standard library) is creating a scoped Error class for the current namespace. There are very few shards I’ve seen that create a scoped Exception class. In these cases—and to be honest, most cases in general—exceptions are errors, so we should just use Error.

5 Likes