NotSerializableException in Java

NotSerializableException:

java.io.NotSerializableException

Thrown when an instance is required to have a Serializable interface. The serialization runtime or the class of the instance can throw this exception. The argument should be the name of the class.

Constructor of NotSerializableException

Example 1:

java.io.NotSerializableException.NotSerializableException()

Constructs a NotSerializableException object.

Java

import java.io.NotSerializableException;

public class NotSerializableExceptionExample {
    public static void main(String[] args) {

        NotSerializableException notSerializableException =
new NotSerializableException();

        System.out.println(notSerializableException);
    }
}

Output:

java.io.NotSerializableException


Example 2:

java.io.NotSerializableException.NotSerializableException(String classname)

Constructs a NotSerializableException object with a message string.

Parameters:

1. classname Class of the instance being serialized/deserialized.

Java

import java.io.NotSerializableException;

public class NotSerializableExceptionExample {
    public static void main(String[] args) {

        NotSerializableException notSerializableException =
new NotSerializableException("classname");

        System.out.println(notSerializableException);
    }
}

Output:

java.io.NotSerializableException: classname


Some other Exceptions of java.io

EOFExceptionSignals that an end of file or end of the stream has been reached unexpectedly during input.

FileNotFoundExceptionSignals that an attempt to open the file denoted by a specified path name has failed.

InterruptedIOExceptionSignals that an I/O operation has been interrupted. 

InvalidClassExceptionThrown when the Serialization runtime detects.

InvalidObjectExceptionIndicates that one or more deserialized objects failed validation tests.

IOErrorThrown when a serious I/O error has occurred.

IOExceptionSignals that an I/O exception of some sort has occurred.

NotActiveExceptionThrown when serialization or deserialization is not active.

ObjectStreamExceptionSuperclass of all exceptions specific to Object Stream classes.

OptionalDataExceptionException 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.

StreamCorruptedExceptionThrown when control information that was read from an object stream violates internal consistency checks.

SyncFailedExceptionSignals that a sync operation has failed.

UncheckedIOExceptionWraps an IOException with an unchecked exception.

UnsupportedEncodingExceptionCharacter Encoding is not supported.

UTFDataFormatExceptionSignals 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.

WriteAbortedExceptionSignals that one of the ObjectStreamExceptions was thrown during a write operation.

No comments:

Post a Comment