Right now we throw a lot of TypeError, ArgumentError, and RuntimeError which are quite generic. It would instead be nice to have a full exception hierarchy used by the library itself to make errors more descriptive to end users and easier to catch. Perhaps something like the following:
An example usage of each is shown below. The BaseError would serve as the catch-all for issues that are not related to serialization/deserialization (for example, context randomization failing).
SerializationError
Raised whenever an attempt to serialize a value fails.
begin
public_key.compressed
rescue Secp256k1::SerializationError => err
end
DeserializationError
Raises whenever parsing of data fails for any reason.
begin
Signature.from_der_encoded(value)
rescue Secp256k1::DeserializationError => err
end
Right now we throw a lot of
TypeError
,ArgumentError
, andRuntimeError
which are quite generic. It would instead be nice to have a full exception hierarchy used by the library itself to make errors more descriptive to end users and easier to catch. Perhaps something like the following:An example usage of each is shown below. The
BaseError
would serve as the catch-all for issues that are not related to serialization/deserialization (for example, context randomization failing).SerializationError Raised whenever an attempt to serialize a value fails.
DeserializationError Raises whenever parsing of data fails for any reason.