/** * Create a new BinaryStreamException. * * @param string $message The human-readable message describing the error. * @param BinaryStream $source The BinaryStream object where in the error occured. * @param integer $code A code describing the error. * @param Exception $previous An optional previous exception. */ public function __construct($message, IStream $source, $code = 0, Exception $previous = null) { parent::__construct($message, $source, $code, $previous); }
/** * Handle a BinaryStreamException in order to throw the relevant BinaryStreamAccessException. * * @param \qtism\common\storage\StreamException $e The StreamException object to deal with. * @param integer $typeError The BinaryStreamAccess exception code to be trown in case of READ error. * @param boolean $read Wheter the error occured in a reading/writing context. * @throws \qtism\common\storage\BinaryStreamAccessException The resulting BinaryStreamAccessException. */ protected function handleBinaryStreamException(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 impossible."; 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; } }