public static GameRecord Decode(BitStream stream) { if (stream.sizeLeft() < 1) return null; GameRecordType type = (GameRecordType)BitOps.ReadByte(stream); GameRecord rec = null; // decoding shouldnt fail with an exception, but Create can be static // in code and should definitely fail try { rec = Create(type); } catch (ArgumentException e) { Log.Error("Failed to decode GameRecord: {0}", e.Message); return null; } // handle any decoding errors try { // first decode the record timestamp // will fail if it fails rec.setTimeStamp(BitOps.ReadUInt64(stream)); bool decodeResult = rec.decode(stream); if (!decodeResult) throw new InvalidOperationException(); } catch (InvalidOperationException) { Log.Error("Failed to decode GameRecord: general decoding error"); return null; } return rec; }