Model Behaviors : How To Catch Errors Raised In The Behaviour's Aftersave?

I’ve got a behaviour, that has an afterSave() method, attached to a model.

The method could error and I want to intercept that somehow, but returning false from the Behaviour’s afterSave method does not return false for $model->save().

I’d like to know if there’s an elegant way to catch this error - other than wrapping a try-catch around $model->save() and throwing an exception in the behaviour.

Right now I’ve declared a public error variable in the model, which the behaviour can set and the model can check.

Model:




public $behaviourAfterSaveResult;



Behaviour:




public function afterSave($event) {

   //processing here, returning boolean $result

   $this->owner->behaviourAfterSaveResult = $result;

}



Controller:




if ($model->save() && $model->behaviourAfterSaveResult) {

   //success

}



Is there a better way?

Thanks!

throwing exception and catching it ouside $model->save() call IS elegant way.

^-- this!