搜索
系统检测到您的用户名不符合规范:

tp6.0.2-Model-抛出异常exception后,无法捕获异常

浏览:1445 发布日期:2020年03月16日
5.0.0 - 严重 - 已关闭
github反馈:
https://github.com/top-think/framework/issues/2205

0、测试环境
Linux

1、定义了 think\exception\Handle 异常托管类

2、当 Model 层的内部抛出异常(由于数据表的pk!=id时,执行Model的软删除操作)
baseQuery throw new Exception —— 'miss update condition'
Handle 将无法捕获,导致没有任何信息输出

3、基于最新的 6.0.2 版本/**
* 保存写入数据
* @access protected
* @return bool
*/
protected function updateData(): bool
{
// 事件回调
if (false === $this->trigger('BeforeUpdate')) {
return false;
}

$this->checkData();

// 获取有更新的数据
$data = $this->getChangedData();

if (empty($data)) {
// 关联更新
if (!empty($this->relationWrite)) {
$this->autoRelationUpdate();
}

return true;
}

if ($this->autoWriteTimestamp && $this->updateTime && !isset($data[$this->updateTime])) {
// 自动写入更新时间
$data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime);
$this->data[$this->updateTime] = $data[$this->updateTime];
}

// 检查允许字段
$allowFields = $this->checkAllowFields();

foreach ($this->relationWrite as $name => $val) {
if (!is_array($val)) {
continue;
}

foreach ($val as $key) {
if (isset($data[$key])) {
unset($data[$key]);
}
}
}

// 模型更新
$db = $this->db();
$db->startTrans();

try {
$this->key = null;
$where = $this->getWhere();

$result = $db->where($where)
->strict(false)
->cache(true)
->setOption('key', $this->key)
->field($allowFields)
->update($data);

$this->checkResult($result);

// 关联更新
if (!empty($this->relationWrite)) {
$this->autoRelationUpdate();
}

$db->commit();

// 更新回调
$this->trigger('AfterUpdate');

return true;
} catch (\Exception $e) {
$db->rollback();
throw $e;
}
}
当 try 的内部抛出异常后,无法 catch 到
评论()
后面还有条评论,
评论支持使用[code][/code]标签添加代码
您需要登录后才可以评论 登录 | 立即注册
提交Bug
langyastudio
积分:233 等级:LV1

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /