Exception: MultiXML::ParseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/multi_xml/errors.rb,
sig/multi_xml.rbs

Overview

Raised when XML parsing fails

Preserves the original XML and underlying cause for debugging.

Examples:

Catching a parse error

begin
  MultiXML.parse('<invalid>')
rescue MultiXML::ParseError => e
  puts e.xml   # The malformed XML
  puts e.cause # The underlying parser exception
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, xml: nil, cause: nil) ⇒ ParseError

Message can be String (normal) or Exception (from parser errors), or nil for default

Parameters:

  • message (?(String | Exception | nil)) (defaults to: nil)
  • xml: (String, nil) (defaults to: nil)
  • cause: (Exception, nil) (defaults to: nil)


40
41
42
43
44
# File 'lib/multi_xml/errors.rb', line 40

def initialize(message = nil, xml: nil, cause: nil)
  @xml = xml
  @cause = cause
  super(message)
end

Instance Attribute Details

#causeException? (readonly)

The underlying parser exception

Examples:

Access the cause

error.cause #=> #<Nokogiri::XML::SyntaxError: ...>

Returns:

  • (Exception, nil)

    the original exception from the parser



29
30
31
# File 'lib/multi_xml/errors.rb', line 29

def cause
  @cause
end

#xmlString? (readonly)

The original XML that failed to parse

Examples:

Access the failing XML

error.xml #=> "<invalid>"

Returns:

  • (String, nil)

    the XML string that caused the error



21
22
23
# File 'lib/multi_xml/errors.rb', line 21

def xml
  @xml
end