Exception: REXML::ParseException

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/rexml/parseexception.rb

Direct Known Subclasses

UndefinedNamespaceException

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, source = nil, parser = nil, exception = nil) ⇒ ParseException

Returns a new instance of ParseException.



6
7
8
9
10
11
# File 'lib/rexml/parseexception.rb', line 6

def initialize( message, source=nil, parser=nil, exception=nil )
  super(message)
  @source = source
  @parser = parser
  @continued_exception = exception
end

Instance Attribute Details

#continued_exceptionObject

Returns the value of attribute continued_exception.



4
5
6
# File 'lib/rexml/parseexception.rb', line 4

def continued_exception
  @continued_exception
end

#parserObject

Returns the value of attribute parser.



4
5
6
# File 'lib/rexml/parseexception.rb', line 4

def parser
  @parser
end

#sourceObject

Returns the value of attribute source.



4
5
6
# File 'lib/rexml/parseexception.rb', line 4

def source
  @source
end

Instance Method Details

#contextObject



49
50
51
# File 'lib/rexml/parseexception.rb', line 49

def context
  @source.current_line
end

#lineObject



44
45
46
47
# File 'lib/rexml/parseexception.rb', line 44

def line
  @source.current_line[2] if @source and defined? @source.current_line and
  @source.current_line
end

#positionObject



39
40
41
42
# File 'lib/rexml/parseexception.rb', line 39

def position
  @source.current_line[0] if @source and defined? @source.current_line and
  @source.current_line
end

#to_sObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rexml/parseexception.rb', line 13

def to_s
  # Quote the original exception, if there was one
  if @continued_exception
    err = @continued_exception.inspect
    err << "\n"
    err << @continued_exception.backtrace.join("\n")
    err << "\n...\n"
  else
    err = ""
  end

  # Get the stack trace and error message
  err << super

  # Add contextual information
  if @source
    err << "\nLine: #{line}\n"
    err << "Position: #{position}\n"
    err << "Last 80 unconsumed characters:\n"
    err.force_encoding("ASCII-8BIT")
    err << @source.buffer[0..80].force_encoding("ASCII-8BIT").gsub(/\n/, ' ')
  end

  err
end