Class NotSerializableException in Java

Share and Enjoy !

Class NotSerializableException in Java

An application that throws NotSerializableException indicates that the target object, that it tried to serialize, could not be serialized. This can happen to classes that do not implement the Serializable interface. A class may implement a Serializable interface but may refer or contain a nonserializable object, in this case when we try to serialize the class, we will get NotSerializableException.

A subclass of a serializable class can prevent itself from being serialized by throwing this (NotSerializableException) exception from its writeObject() or readObject() methods.

It is a child class of ObjectSreamException and is common exception classes in java.

The structure of the NotSerializableException class given as :

public class extends{
public NotSerializableException();
public NotSerializableException(String className);

The details of the class method description is given as:

public NotSerializableException();

public NotSerializableException() constructor creates a NotSerializableException with no class name.

public NotSerializableException(String className);

public NotSerializableException(String className) constructor creates a NotSerializableException with the specified class name.
classname-The name of the class that can’t be serialized.

The class NotSerializableException also inherits methods from class Object and Throwable.

From Object classFrom Throwable class
wait(long, int)getLocalizedMessage()

Share and Enjoy !

READ  How to Create Executable or Normal Jar File in Java?

Leave a Reply

Your email address will not be published. Required fields are marked *