protected function handleStreamException(StreamException $e, $typeError, $read = true)
    {
        $strType = 'unknown datatype';

        switch ($typeError) {
            case BinaryStreamAccessException::BOOLEAN:
                $strType = 'boolean';
            break;

            case BinaryStreamAccessException::BINARY:
                $strType = 'binary data';
            break;

            case BinaryStreamAccessException::FLOAT:
                $strType = 'double precision float';
            break;

            case BinaryStreamAccessException::INT:
                $strType = 'integer';
            break;

            case BinaryStreamAccessException::SHORT:
                $strType = 'short integer';
            break;

            case BinaryStreamAccessException::STRING:
                $strType = 'string';
            break;

            case BinaryStreamAccessException::TINYINT:
                $strType = 'tiny integer';
            break;

            case BinaryStreamAccessException::DATETIME:
                $strType = 'datetime';
            break;
        }

        $strAction = ($read === true) ? 'reading' : 'writing';

        switch ($e->getCode()) {
            case StreamException::NOT_OPEN:
                $strAction = ucfirst($strAction);
                $msg = "${strAction} a ${strType} from a closed binary stream is not permitted.";
                throw new BinaryStreamAccessException($msg, $this, BinaryStreamAccessException::NOT_OPEN, $e);
                break;

            case StreamException::READ:
                $msg = "An error occured while ${strAction} a ${strType}.";
                throw new BinaryStreamAccessException($msg, $this, $typeError, $e);
                break;

            default:
                $msg = "An unknown error occured while ${strAction} a ${strType}.";
                throw new BinaryStreamAccessException($msg, $this, BinaryStreamAccessException::UNKNOWN, $e);
                break;
        }
    }