Exception: REXML::ParseException

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/extensions/rexml/rexml/parseexception.rb,
lib/extensions/rhoxml/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.



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

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.



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

def continued_exception
  @continued_exception
end

#parserObject

Returns the value of attribute parser.



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

def parser
  @parser
end

#sourceObject

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#contextObject



47
48
49
# File 'lib/extensions/rexml/rexml/parseexception.rb', line 47

def context
  @source.current_line
end

#lineObject



42
43
44
45
# File 'lib/extensions/rexml/rexml/parseexception.rb', line 42

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

#positionObject



37
38
39
40
# File 'lib/extensions/rexml/rexml/parseexception.rb', line 37

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

#to_sObject



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

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 << @source.buffer[0..80].gsub(/\n/, ' ')
  end
  
  err
end