Throwing an exception only if the object can't be serialized.