多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] ## BadFunctionCallException — 无效回调函数 如果回调引用未定义的函数或缺少某些参数,则抛出异常。 ## BadMethodCallException — 无效回调方法 当一个回调方法是一个未定义的方法或缺失一些参数时会抛出该异常。 ## DomainException — 值不符合定义的有效数据域 实例1 ``` function media($x) { switch ($x) { case image: return 'PNG'; break; case video: return 'MP4'; break; default: throw new InvalidArgumentException ("Invalid media type!"); } } ``` 实例2 ``` function divide($divident, $divisor) { if(!is_numeric($divident) || !is_numeric($divisor)) { throw new InvalidArgumentException("Function accepts only numeric values"); } if($divisor == 0) { throw new DomainException("Divisor must not be zero"); } return $divident / $divisor; } ``` ## InvalidArgumentException — 无效参数 ``` function tripleInteger($int) { if(!is_int($int)) throw new InvalidArgumentException('tripleInteger function only accepts integers. Input was: '.$int); return $int * 3; } ``` ## LengthException — 长度错误 ## LogicException — 逻辑错误 表示程序逻辑错误的异常。这种异常应直接导致代码中的修复。 ## OutOfBoundsException — 必要值不存在 如果值不是有效键,则抛出异常。这表示在编译时无法检测到的错误。 ``` class HandleApplication { public function __construct($_POST) { if(!isset($_POST['secretCode']) throw new OutOfBoundsException('Application hasn't sent secret code for authenticate'); } ``` ## OutOfRangeException — The OutOfRangeException class 请求非法索引时引发异常。这表示应在编译时检测到的错误。 ``` function prepareData(PDOStatement $s) { $x = $s->fetch(); if (!isset($x['secretColumn'])) throw new OutOfRangeException ("Secret column doesn't exist! Verify table definition and query."); } ``` ## OverflowException — The OverflowException class 将元素添加到完整容器中时引发异常。 ## RangeException — 无效范围 ## RuntimeException — 运行时错误 如果发生仅在运行时才能发现的错误,则引发异常。 ## UnderflowException — 对容器的无效操作 对空容器执行无效操作(例如删除元素)时引发的异常。 ## UnexpectedValueException — 非期望值异常 如果值与一组值不匹配,则抛出异常