Exception: Encoding::InvalidByteSequenceError
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
EncodingError
|
Defined in: | transcode.c, transcode.c |
Overview
Raised by ::Encoding and ::String methods when the string being transcoded contains a byte invalid for the either the source or target encoding.
Class Method Summary
::Exception - Inherited
.exception | With no argument, or if the argument is the same as the receiver, return the receiver. |
.new | Construct a new ::Exception object, optionally passing in a message. |
Instance Attribute Summary
-
#incomplete_input? ⇒ Boolean
readonly
Returns true if the invalid byte sequence error is caused by premature end of string.
Instance Method Summary
- #destination_encoding ⇒ String
- #destination_encoding_name ⇒ String
-
#error_bytes ⇒ String
Returns the discarded bytes when
InvalidByteSequenceError
occurs. -
#readagain_bytes ⇒ String
Returns the bytes to be read again when
InvalidByteSequenceError
occurs. -
#source_encoding ⇒ Encoding
Alias for UndefinedConversionError#source_encoding.
- #source_encoding_name ⇒ String
::Exception - Inherited
#== | Equality—If obj is not an ::Exception, returns |
#backtrace | Returns any backtrace associated with the exception. |
#backtrace_locations | Returns any backtrace associated with the exception. |
#cause | Returns the previous exception ($!) at the time this exception was raised. |
#exception | With no argument, or if the argument is the same as the receiver, return the receiver. |
#inspect | Return this exception's class name and message. |
#message | Returns the result of invoking |
#set_backtrace | Sets the backtrace information associated with |
#to_s | Returns exception's message (or the name of the exception if no message is set). |
Constructor Details
This class inherits a constructor from Exception
Instance Attribute Details
#incomplete_input? ⇒ Boolean
(readonly)
Returns true if the invalid byte sequence error is caused by premature end of string.
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
begin
ec.convert("abc\xA1z")
rescue Encoding::InvalidByteSequenceError
p $! #=> #<Encoding::InvalidByteSequenceError: "\xA1" followed by "z" on EUC-JP>
p $!.incomplete_input? #=> false
end
begin
ec.convert("abc\xA1")
ec.finish
rescue Encoding::InvalidByteSequenceError
p $! #=> #<Encoding::InvalidByteSequenceError: incomplete "\xA1" on EUC-JP>
p $!.incomplete_input? #=> true
end
Instance Method Details
#destination_encoding ⇒ String
#destination_encoding_name ⇒ String
#error_bytes ⇒ String
Returns the discarded bytes when InvalidByteSequenceError
occurs.
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
begin
ec.convert("abc\xA1\xFFdef")
rescue Encoding::InvalidByteSequenceError
p $! #=> #<Encoding::InvalidByteSequenceError: "\xA1" followed by "\xFF" on EUC-JP>
puts $!.error_bytes.dump #=> "\xA1"
puts $!.readagain_bytes.dump #=> "\xFF"
end
#readagain_bytes ⇒ String
Returns the bytes to be read again when InvalidByteSequenceError
occurs.
#source_encoding ⇒ Encoding
Alias for UndefinedConversionError#source_encoding.