posted 15 years ago
Catch or re-throw ClassNotFoundException.
I'll explain the reason why ObjectInputStream.readObject() can throw this exception with this little example:
You have an instance of class X. You serialize this instance to a file, and then give the file to someone else. This other person does not have class X on his class path. He then tries to de-serialize the file. The de-serialization tries to find class X but it can't find it. It doesn't know what to do so it throws an exception. It could have thrown an IOException but a ClassNotFoundException makes it clearer what the exact problem is - a missing class file.