InvalidClassException:
java.io.InvalidClassException
Thrown when the Serialization runtime detects one of the following problems
with a Class.
1. The serial version of the class does not match that of the class descriptor read from the stream.
2. The class contains unknown datatypes.
3. The class does not have an accessible no-arg constructor.
4. The ObjectStreamClass of an enum constant does not represent enum type.
Constructor of InvalidClassException
Example 1:
java.io.InvalidClassException.InvalidClassException(String reason)
Report an InvalidClassException for the reason specified.
Parameters:
1. reason String describing the reason for the exception.
Java
import java.io.InvalidClassException;public class InvalidClassExceptionExample {public static void main(String[] args) {InvalidClassException invalidClassException =new InvalidClassException("reason");System.out.println(invalidClassException);}}
Output:
java.io.InvalidClassException: reason
Example 2:
java.io.InvalidClassException.InvalidClassException(String cname, String reason)
Constructs an InvalidClassException object.
Parameters:
1. cname a String naming the invalid class.
2. reason a String describing the reason for the exception.
Java
import java.io.InvalidClassException;public class InvalidClassExceptionExample {public static void main(String[] args) {InvalidClassException invalidClassException =new InvalidClassException("cname", "reason");System.out.println(invalidClassException);}}
Output:
java.io.InvalidClassException: cname; reason
Some other Exceptions of java.io
EOFException: Signals that an end of file or end of the stream has been reached unexpectedly during input.
FileNotFoundException: Signals that an attempt to open the file denoted by a specified path name has failed.
InterruptedIOException: Signals that an I/O operation has been interrupted.
InvalidObjectException: Indicates that one or more deserialized objects failed validation tests.
IOError: Thrown when a serious I/O error has occurred.
IOException: Signals that an I/O exception of some sort has occurred.
NotActiveException: Thrown when serialization or deserialization is not active.
NotSerializableException: Thrown when an instance is required to have a Serializable interface.
ObjectStreamException: Superclass of all exceptions specific to Object Stream classes.
OptionalDataException: Exception indicating the failure of an object read operation due to unread primitive data, or the end of data belonging to a serialized object in the stream.
StreamCorruptedException: Thrown when control information that was read from an object stream violates internal consistency checks.
SyncFailedException: Signals that a sync operation has failed.
UncheckedIOException: Wraps an IOException with an unchecked exception.
UnsupportedEncodingException: Character Encoding is not supported.
UTFDataFormatException: Signals that a malformed string in modified UTF-8 format has been read in a data input stream or by any class that implements the data input interface.
WriteAbortedException: Signals that one of the ObjectStreamExceptions was thrown during a write operation.
No comments:
Post a Comment