Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need serialVersionUID when extending RuntimeException?

Why do we need serialVersionUID when extending RuntimeException? Is RuntimeException a serializable class?

public class DataNotFoundException extends RuntimeException {       
    /**
     * 
     */
    private static final long serialVersionUID = 1;

    public DataNotFoundException(String str)
    {
        super(str);
    }
}
like image 318
yogesh sharma Avatar asked Oct 06 '17 05:10

yogesh sharma


2 Answers

RuntimeException extends Exception. Exception extends Throwable. Throwable implements Serializable. So DataNotFoundException is Serializable too

like image 102
Evgeniy Dorofeev Avatar answered Oct 01 '22 21:10

Evgeniy Dorofeev


Yes, Throwables are Serializable. Serializable means that objects of that class can be converted into a sequence of bytes. Making an exception serializable means it can be transferred across the network between tiers of a distributed application.

like image 24
Nathan Hughes Avatar answered Oct 01 '22 20:10

Nathan Hughes