Class NotSerializableException in Java

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.

Ads code goes here

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

The structure of the NotSerializableException class given as :

public class java.io.NotSerializableException extends java.io.ObjectStreamException{
//constructors:
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.
Parameter
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
clone()fillInStackTrace()
getClass()getMessage()
notify()printStackTrace()
wait()printStackTrace(PrintWriter)
wait(long, int)getLocalizedMessage()
wait(long)printStackTrace(PrintStream)
equals(Object)
toString()
finalize()
hashCode()
notifyAll()

Share and Enjoy !

READ  Class URLEncoder in Java

Leave a Comment

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