Exception Encoding version 1.0
An exception is marshaled as shown below:
Marshaling format for exceptions.
Every exception instance is preceded by a single byte that indicates whether the exception uses class members: the byte value is 1
if any of the exception members are classes (or if any of the exception members, recursively, contain class members) and 0
, otherwise.
Following the header byte, the exception is marshaled as a sequence of pairs: the first member of each pair is the type ID for an exception slice, and the second member of the pair is a slice containing the marshaled members of that slice. The sequence of pairs is marshaled in derived-to-base order, with the most-derived slice first, and ending with the least-derived slice. Within each slice, data members are marshaled as for structures: in the order in which they are defined in the Slice definition.
Following the sequence of pairs, any class instances that are used by the members of the exception are marshaled. This final part is optional: it is present only if the header byte is 1
.
To illustrate the marshaling, consider the following exception hierarchy:
exception Base { int baseInt; string baseString; }; exception Derived extends Base { bool derivedBool; string derivedString; double derivedDouble; };
Assume that the exception members are initialized to the values shown below:
Member | Type | Value | Marshaled size (in bytes) |
---|---|---|---|
|
|
| 4 |
|
|
| 6 |
|
|
| 1 |
|
|
| 7 |
|
|
| 8 |
Member values of an exception of type Derived
.
From the above table, we can see that the total size of the members of Base
is 10 bytes, and the total size of the members of Derived
is 16 bytes. None of the exception members are classes. An instance of this exception has the on-the-wire representation shown in the next table. (The size, type, and byte offset of the marshaled representation is indicated for each component.)
Marshaled value | Size in bytes | Type | Byte offset |
---|---|---|---|
| 1 |
| 0 |
| 10 |
| 1 |
| 4 |
| 11 |
| 1 |
| 15 |
| 7 |
| 16 |
| 8 |
| 23 |
| 7 |
| 31 |
| 4 |
| 38 |
| 4 |
| 42 |
| 6 |
| 46 |
Marshaled representation of the exception.
Note that the size of each string is one larger than the actual string length. This is because each string is preceded by a count of its number of bytes, as directed by the encoding for strings.
The receiver of this sequence of values uses the header byte to decide whether it eventually must unmarshal any class instances contained in the exception (none in this example) and then examines the first type ID (::Derived
). If the receiver recognizes that type ID, it can unmarshal the contents of the first slice, followed by the remaining slices; otherwise, the receiver reads the byte count that follows the unknown type (20) and then skips 20-4 bytes in the input stream, which is the start of the type ID for the second slice (::Base
). If the receiver does not recognize that type ID either, it again reads the byte count following the type ID (14), skips 14-4 bytes, and attempts to read another type ID. (This can happen only if client and server have been compiled with mismatched Slice definitions that disagree in the exception specification of an operation.) In this case, the receiver will eventually encounter an unmarshaling error, which it can report with a MarshalException
.
If an exception contains class members, these members are marshaled following the exception slices as described in the class encoding.
Exception Encoding version 1.1
An exception is marshaled as a collection of slices whose order matches the inheritance hierarchy, with the most-derived type appearing first. The selected encoding format affects the content of each slice. The final slice, representing the least-derived type, has its last slice bit set to true.
An exception in the compact format is marshaled as follows:
Compact format for exceptions.
The leading byte of each slice is a set of bit flags that specifies the features of the slice. The compact format includes a type ID in the initial (most-derived) slice but omits the type ID from all subsequent slices.
The sliced format includes a type ID in every slice, along with a slice size and an optional indirection table:
Sliced format for exceptions.
To illustrate the marshaling, consider the following exception hierarchy:
exception Base { int baseInt; string baseString; }; exception Derived extends Base { bool derivedBool; string derivedString; double derivedDouble; };
Assume that the exception members are initialized to the values shown below:
Member | Type | Value | Marshaled size (in bytes) |
---|---|---|---|
|
|
| 4 |
|
|
| 6 |
|
|
| 1 |
|
|
| 7 |
|
|
| 8 |
Member values of an exception of type Derived
.
From the above table, we can see that the total size of the members of Base
is 10 bytes, and the total size of the members of Derived
is 16 bytes. None of the exception members are classes. An instance of this exception using the sliced format has the on-the-wire representation shown in the next table. (The size, type, and byte offset of the marshaled representation is indicated for each component.)
Marshaled value | Size in bytes | Type | Byte offset |
---|---|---|---|
| 1 |
| 0 |
| 10 |
| 1 |
| 4 |
| 11 |
| 1 |
| 15 |
| 7 |
| 16 |
| 8 |
| 23 |
| 1 |
| 31 |
| 7 |
| 32 |
| 4 |
| 39 |
| 4 |
| 43 |
| 6 |
| 47 |
Marshaled representation of the exception using the sliced format.
Note that the size of each string is one larger than the actual string length. This is because each string is preceded by a count of its number of bytes, as directed by the encoding for strings.
Repeating this exercise using the compact format produces the following encoding:
Marshaled value | Size in bytes | Type | Byte offset |
---|---|---|---|
| 1 |
| 0 |
| 10 |
| 1 |
| 1 |
| 11 |
| 7 |
| 12 |
| 8 |
| 19 |
| 1 |
| 27 |
| 4 |
| 28 |
| 6 |
| 32 |
Marshaled representation of the exception using the compact format.
When using the compact format, the receiver must know the most-derived type: the only type ID included in the encoding is that of the most-derived type. Furthermore, the lack of slice sizes means the receiver cannot skip a slice without knowing how to decode its contents.
See Also