Catching serialization error proper way