Difficulty With Exception Handling

Hi hope you are well,

Im still fairly new to YII, and is still learning the framework.

I have been reading about ways to handle exceptions in yii. The method which seemed appealing was using a handler in my config/main as :-

'onException' => function($event)


   if ($event->exception instanceof CDbException)


      // true means, mark the event as handled so that no other handler will

      // process the event (the Yii exception handler included).

      $event->handled = true;



This approach seems easy, but how can I give a more specific error message for an event arisen?

For example, a CDbException instance can be arisen by a duplicate entry to DB as well as for some other reason. Is there a way to distinguish between the two?

Any reading material or a proper method to handle an exception is greatly appreciated.

Thanks a lot for your time!



can anyone please help me?

hope this link will answer for you


Thanks a lot for the reply…!

I’ll see to it…!

Cheerz! :)