Added additional encoding/decoding exception checks.