Exception: MultiJson::Adapters::Oj::ParseError

Inherits:
SyntaxError
  • Object
show all
Defined in:
lib/multi_json/adapters/oj.rb

Overview

In certain cases OJ gem may throw JSON::ParserError exception instead of its own class. Also, we can’t expect ::JSON::ParserError and ::Oj::ParseError to always be defined, since it’s often not the case. Because of this, we can’t reference those classes directly and have to do string comparison instead. This will not catch subclasses, but it shouldn’t be a problem since the library is not known to be using it (at least for now).

Class Method Summary collapse

Class Method Details

.===(exception) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Case equality for exception matching in rescue clauses

Examples:

Match parse errors in rescue

rescue ParseError => e

Parameters:

  • exception (Exception)

    exception to check

Returns:

  • (Boolean)

    true if exception is a parse error



33
34
35
# File 'lib/multi_json/adapters/oj.rb', line 33

def self.===(exception)
  exception.is_a?(::SyntaxError) || WRAPPED_CLASSES.include?(exception.class.to_s)
end