Spread the love

Class InvalidClassException in Java

Spread the love

Class InvalidClassException in Java

This exception signals that the serialization mechanism has encountered one of several possible problems with the class of an object that is being serialized or deserialized. The classname field should contain the name of the class in question, and the getMessage() method is overridden to return this class name with the message.

An InvalidClassException is thrown during object serialization. It indicates that the run-time
environment does not support a serialized class for one of the following reasons:

  • The version of the class does not match the serial version of the class in the stream.
  • The class contains unknown data types.
  • An InvalidClassException can also indicate one of these problems with the class itself:
  • The class implements only one of writeObject() and readObject().
  • The class is not public.
  • The class does not have an accessible constructor that takes no arguments.

The structure of the class InvalidClassException is as follows:

public class java.io.InvalidClassException extends java.io.ObjectStreamException{
// Public Constructors
public InvalidClassException(String reason);
public InvalidClassException(String cname, String reason);
// Public Instance Variables
public String classname;
// Public Instance Methods
public String getMessage(); // Overrides Throwable
}

The details of the class structure are given as:

public InvalidClassException(String reason);

public InvalidClassException(String reason) constructor creates an InvalidClassException with the specified reason string.

Parameter
reason-The reason the exception was thrown.

public InvalidClassException(String cname, String reason);

public InvalidClassException(String cname, String reason) constructor creates an InvalidClassException with the specified class name and reason string.

READ  Class StringBuffer in Java
READ  Class IOException in Java

Parameter
cname-The name of the class.
reason-The reason the exception was thrown

public String classname;

public String classname is the name of the class that caused the exception

public String getMessage();

public String getMessage() method returns the reason string for this exception. If a class name has also been specified, it is prepended to the reason string with a semicolon.
This method returns the reason string for this exception.
The class InvalidClassException 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()




Spread the love
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Learn How to Use Jacoco Java code Coverage

Introduction to Jacoco Jacoco provides a wide range of coverage(analysis of instructions,...

Comments

Recent Posts

Learn Quickly About DevOps Tools in a Fast and Efficient Manner

Introduction to DevOps tools DevOps tools are a collection of...

How to Collaborate between Development and Operations Team Fast and Effectively

Collaborate between Development and Operations Teams are the key...

Learn How to Use Jacoco Java code Coverage

Introduction to Jacoco Jacoco provides a wide range of coverage(analysis...

EDITOR PICKS


Spread the love