44787
|
1 |
---
|
|
2 |
# Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
#
|
|
5 |
# This code is free software; you can redistribute it and/or modify it
|
|
6 |
# under the terms of the GNU General Public License version 2 only, as
|
|
7 |
# published by the Free Software Foundation.
|
|
8 |
#
|
|
9 |
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
# version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
# accompanied this code).
|
|
14 |
#
|
|
15 |
# You should have received a copy of the GNU General Public License version
|
|
16 |
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
#
|
|
19 |
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
# or visit www.oracle.com if you need additional information or have any
|
|
21 |
# questions.
|
|
22 |
|
|
23 |
include-before: '[CONTENTS](index.html) | [PREV](security.html) | [NEXT](examples.html)'
|
|
24 |
include-after: '[CONTENTS](index.html) | [PREV](security.html) | [NEXT](examples.html)'
|
|
25 |
|
|
26 |
title: 'Java Object Serialization Specification: B - Exceptions In Object Serialization'
|
|
27 |
---
|
|
28 |
|
|
29 |
-------------------------------------------------------------------------------
|
|
30 |
|
|
31 |
All exceptions thrown by serialization classes are subclasses of
|
|
32 |
`ObjectStreamException` which is a subclass of `IOException`.
|
|
33 |
|
|
34 |
### `ObjectStreamException`
|
|
35 |
|
|
36 |
Superclass of all serialization exceptions.
|
|
37 |
|
|
38 |
### `InvalidClassException`
|
|
39 |
|
|
40 |
Thrown when a class cannot be used to restore objects for any of these reasons:
|
|
41 |
|
|
42 |
- The class does not match the serial version of the class in the stream.
|
|
43 |
- The class contains fields with invalid primitive data types.
|
|
44 |
- The `Externalizable` class does not have a public no-arg constructor.
|
|
45 |
- The `Serializable` class can not access the no-arg constructor of its
|
|
46 |
closest non-Serializable superclass.
|
|
47 |
|
|
48 |
### `NotSerializableException`
|
|
49 |
|
|
50 |
Thrown by a `readObject` or `writeObject` method to terminate serialization or
|
|
51 |
deserialization.
|
|
52 |
|
|
53 |
### `StreamCorruptedException`
|
|
54 |
|
|
55 |
Thrown:
|
|
56 |
|
|
57 |
- If the stream header is invalid.
|
|
58 |
- If control information not found.
|
|
59 |
- If control information is invalid.
|
|
60 |
- JDK 1.1.5 or less attempts to call `readExternal` on a `PROTOCOL_VERSION_2`
|
|
61 |
stream.
|
|
62 |
|
|
63 |
### `NotActiveException`
|
|
64 |
|
|
65 |
Thrown if `writeObject` state is invalid within the following
|
|
66 |
`ObjectOutputStream` methods:
|
|
67 |
|
|
68 |
- `defaultWriteObject`
|
|
69 |
- `putFields`
|
|
70 |
- `writeFields`
|
|
71 |
|
|
72 |
Thrown if `readObject` state is invalid within the following
|
|
73 |
`ObjectInputStream` methods:
|
|
74 |
|
|
75 |
- `defaultReadObject`
|
|
76 |
- `readFields`
|
|
77 |
- `registerValidation`
|
|
78 |
|
|
79 |
### `InvalidObjectException`
|
|
80 |
|
|
81 |
Thrown when a restored object cannot be made valid.
|
|
82 |
|
|
83 |
### `OptionalDataException`
|
|
84 |
|
|
85 |
Thrown by `readObject` when there is primitive data in the stream and an object
|
|
86 |
is expected. The length field of the exception indicates the number of bytes
|
|
87 |
that are available in the current block.
|
|
88 |
|
|
89 |
### `WriteAbortedException`
|
|
90 |
|
|
91 |
Thrown when reading a stream terminated by an exception that occurred while the
|
|
92 |
stream was being written.
|
|
93 |
|
|
94 |
-------------------------------------------------------------------------------
|
|
95 |
|
|
96 |
*[Copyright](../../../legal/SMICopyright.html) © 2005, 2017, Oracle
|
|
97 |
and/or its affiliates. All rights reserved.*
|