A
A
Alex1222016-11-20 19:21:03
Yii
Alex122, 2016-11-20 19:21:03

What to throw an exception or error in yii2?

Hello! I save the image in yii2 using saveAs(), which exception is better to throw if this function returns false, so that later I can quickly determine where the error lies? Or is it not worth throwing at all, what do you think? Thank you)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-11-20
@Alex122

Usually they do not throw an error, but return the model with validation errors, so you can simply add an error to $model->errors so that activeform displays it.
But if this is for example ajax, then you can also throw an error, for example like this:

if(!$file->saveAs()){
throw new yii\base\ErrorException('ошибка при сохранении файла');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question