Crystal exceptions and errors

This is a common question. In Crystal, what is the difference between Exceptionand Error?

For example, the package JSONhas JSON::Errorand JSON::ParseException, which inherits from JSON::Error. Also, how do we know if a method can raise Exception(or Error, I really don't know the difference)?

+4
source share
1 answer

There is no difference between Errorand Exception, it's just a contradictory naming convention.

It probably should be standardized someday. The IIRC consensus was mainly use Exceptiononly for a common base class and use Errorfor all implementations for specific errors. In this scheme JSON::ParseExceptionshould be JSON::ParseError.

, , ( ). , .

+5

Source: https://habr.com/ru/post/1691860/


All Articles