123456789_123456789_123456789_123456789_123456789_

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 true if exception messages will be sent to a tty.

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

Instance Method Summary

::Exception - Inherited

#==

Equality—If obj is not an ::Exception, returns false.

#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 exception.to_s.

#set_backtrace

Sets the backtrace information associated with exc.

#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
[ GitHub ]

  
# File 'transcode.c', line 4389

static VALUE
ecerr_incomplete_input(VALUE self)
{
    return rb_attr_get(self, rb_intern("incomplete_input"));
}

Instance Method Details

#destination_encodingString

#destination_encoding_nameString

#error_bytesString

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
[ GitHub ]

  
# File 'transcode.c', line 4347

static VALUE
ecerr_error_bytes(VALUE self)
{
    return rb_attr_get(self, rb_intern("error_bytes"));
}

#readagain_bytesString

Returns the bytes to be read again when InvalidByteSequenceError occurs.

[ GitHub ]

  
# File 'transcode.c', line 4359

static VALUE
ecerr_readagain_bytes(VALUE self)
{
    return rb_attr_get(self, rb_intern("readagain_bytes"));
}

#source_encodingEncoding

#source_encoding_nameString