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 Attribute Summary
::Exception
- Inherited
.to_tty? | Returns |
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 |
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 |
#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. |
#full_message | Returns formatted string of exception. |
#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
# File 'transcode.c', line 4390
static VALUE ecerr_incomplete_input(VALUE self) { return rb_attr_get(self, rb_intern("incomplete_input")); }
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
# File 'transcode.c', line 4348
static VALUE ecerr_error_bytes(VALUE self) { return rb_attr_get(self, rb_intern("error_bytes")); }
#readagain_bytes ⇒ String
Returns the bytes to be read again when InvalidByteSequenceError
occurs.
# File 'transcode.c', line 4360
static VALUE ecerr_readagain_bytes(VALUE self) { return rb_attr_get(self, rb_intern("readagain_bytes")); }
#source_encoding ⇒ Encoding
Alias for UndefinedConversionError#source_encoding.