Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question