Exception: HexaPDF::MalformedPDFError

Inherits:
Error
  • Object
show all
Defined in:
lib/hexapdf/error.rb

Overview

Raised when the PDF is invalid and can’t be read correctly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg_or_error, pos: nil) ⇒ MalformedPDFError

Creates a new malformed PDF error object for the given exception or exception message.

The byte position where the error occured can be given via the optional pos argument.



48
49
50
51
52
# File 'lib/hexapdf/error.rb', line 48

def initialize(msg_or_error, pos: nil)
  super(msg_or_error)
  set_backtrace(msg_or_error.backtrace) if msg_or_error.kind_of?(Exception)
  @pos = pos
end

Instance Attribute Details

#posObject (readonly)

The byte position in the PDF file where the error occured.



43
44
45
# File 'lib/hexapdf/error.rb', line 43

def pos
  @pos
end

Instance Method Details

#messageObject

:nodoc:



54
55
56
57
# File 'lib/hexapdf/error.rb', line 54

def message # :nodoc:
  pos_msg = @pos.nil? ? '' : " around position #{pos}"
  "PDF malformed#{pos_msg}: #{super}"
end