基于PHP7.1版本使用Catch多个语句

pull/385/head
Henry 2022-02-17 14:54:57 +08:00
parent 6470a8ed74
commit 2a97c21c0c
1 changed files with 6 additions and 30 deletions

View File

@ -110,13 +110,7 @@ trait Backend
} }
$result = $this->model->allowField(true)->save($params); $result = $this->model->allowField(true)->save($params);
Db::commit(); Db::commit();
} catch (ValidateException $e) { } catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback(); Db::rollback();
$this->error($e->getMessage()); $this->error($e->getMessage());
} }
@ -161,13 +155,7 @@ trait Backend
} }
$result = $row->allowField(true)->save($params); $result = $row->allowField(true)->save($params);
Db::commit(); Db::commit();
} catch (ValidateException $e) { } catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback(); Db::rollback();
$this->error($e->getMessage()); $this->error($e->getMessage());
} }
@ -207,10 +195,7 @@ trait Backend
$count += $v->delete(); $count += $v->delete();
} }
Db::commit(); Db::commit();
} catch (PDOException $e) { } catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback(); Db::rollback();
$this->error($e->getMessage()); $this->error($e->getMessage());
} }
@ -248,10 +233,7 @@ trait Backend
$count += $v->delete(true); $count += $v->delete(true);
} }
Db::commit(); Db::commit();
} catch (PDOException $e) { } catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback(); Db::rollback();
$this->error($e->getMessage()); $this->error($e->getMessage());
} }
@ -288,10 +270,7 @@ trait Backend
$count += $item->restore(); $count += $item->restore();
} }
Db::commit(); Db::commit();
} catch (PDOException $e) { } catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback(); Db::rollback();
$this->error($e->getMessage()); $this->error($e->getMessage());
} }
@ -327,10 +306,7 @@ trait Backend
$count += $item->allowField(true)->isUpdate(true)->save($values); $count += $item->allowField(true)->isUpdate(true)->save($values);
} }
Db::commit(); Db::commit();
} catch (PDOException $e) { } catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback(); Db::rollback();
$this->error($e->getMessage()); $this->error($e->getMessage());
} }