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 terminal device.

Class Method Summary

::Exception - Inherited

.exception

Returns an exception object of the same class as self; useful for creating a similar exception, but with a different message.

.new

Returns a new exception object.

Instance Attribute Summary

Instance Method Summary

::Exception - Inherited

#==

Returns whether other is the same class as self and its #message and #backtrace are equal to those of self.

#backtrace

Returns the backtrace (the list of code locations that led to the exception), as an array of strings.

#backtrace_locations

Returns the backtrace (the list of code locations that led to the exception), as an array of ::Thread::Backtrace::Location instances.

#cause

Returns the previous value of global variable $!, which may be nil (see Global Variables):

#detailed_message

Returns the message string with enhancements:

#exception

Returns an exception object of the same class as self; useful for creating a similar exception, but with a different message.

#full_message

Returns an enhanced message string:

#inspect

Returns a string representation of self:

#message

Returns #to_s.

#set_backtrace

Sets the backtrace value for self; returns the given value.

#to_s

Returns a string representation of self:

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 4499

static VALUE
ecerr_incomplete_input(VALUE self)
{
    return rb_attr_get(self, id_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 4457

static VALUE
ecerr_error_bytes(VALUE self)
{
    return rb_attr_get(self, id_error_bytes);
}

#readagain_bytesString

Returns the bytes to be read again when InvalidByteSequenceError occurs.

[ GitHub ]

  
# File 'transcode.c', line 4469

static VALUE
ecerr_readagain_bytes(VALUE self)
{
    return rb_attr_get(self, id_readagain_bytes);
}

#source_encodingEncoding

#source_encoding_nameString