yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework

Home Page:http://www.yiiframework.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BaseActiveRecord save method behaviour

zebraf1 opened this issue · comments

When calling save() on a model object, it hints that it returns true or false whether save succeeded. It does not hint any exceptions are thrown, however it calls insert() or update() which can throw db\Exception or Throwable.
So when the database configuration is wrong or database is not responsing then an Exception is thrown from save() and causes an unexpected error.

Either:
a) the exceptions should be caught within save(), logged and returns false
b) PHP doc for save() needs to be updated with [at]throws statement, so IDE's can detect it needs exception handling

Solution b) is preferred. Could you make a pull request?