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 | Returns an exception object of the same class as |
.new | Returns a new exception object. |
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
#== | Returns whether |
#backtrace | Returns a backtrace value for |
#backtrace_locations | Returns a backtrace value for |
#cause | Returns the previous value of global variable |
#detailed_message | Returns the message string with enhancements: |
#exception | Returns an exception object of the same class as |
#full_message | Returns an enhanced message string: |
#inspect | Returns a string representation of |
#message | Returns #to_s. |
#set_backtrace | Sets the backtrace value for |
#to_s | Returns a string representation of |
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 4428
static VALUE ecerr_incomplete_input(VALUE self) { return rb_attr_get(self, id_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 4386
static VALUE ecerr_error_bytes(VALUE self) { return rb_attr_get(self, id_error_bytes); }
#readagain_bytes ⇒ String
Returns the bytes to be read again when InvalidByteSequenceError
occurs.
# File 'transcode.c', line 4398
static VALUE ecerr_readagain_bytes(VALUE self) { return rb_attr_get(self, id_readagain_bytes); }
#source_encoding ⇒ Encoding
Alias for UndefinedConversionError#source_encoding.