Code example for InvalidObjectException

0
            } 
 
            public Object writeReplace() throws ObjectStreamException {
                switch (type) {
                case 0: 
                    throw new InvalidObjectException("invalid");
                case 1: 
                    throw new RuntimeException("runtime");
                case 2: 
                    throw new Error("error");
                default: 
                    return new ReadResolveTestE(readType);
                } 
            } 
        } 
 
        static class ReadResolveTestA implements Serializable {
            public Object readResolve() throws ObjectStreamException {
                return new ReadResolveTestA(); 
            } 
        }