Reputation: 57
This is a general question. In Crystal, what is the difference between an Exception
and an Error
?
For example, in the JSON
package, there is both JSON::Error
and a JSON::ParseException
, which inherits from JSON::Error
. Also, how do we know if a method might raise an Exception
(or Error
, I really don't know the difference)?
Upvotes: 4
Views: 140
Reputation: 5661
There is no difference between Error
and Exception
, it's just inconsistent naming.
That should probably be standardized some day. IIRC the consensus was mostly to use Exception
only for the general base class and use Error
for all implementations for specific errors. In that scheme, JSON::ParseException
should actually be JSON::ParseError
.
Method descriptions should typically state which errors can be thrown, but this might not be a conclusive list (if at all). There is no way to semantically deduce all exception types that can be thrown by a specific method.
Upvotes: 5