Yii Framework Forum: Yii2 - error handler can not catches database exceptions - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii2 - error handler can not catches database exceptions

#1 User is offline   hamed1991 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 20-March 14
  • Location:Iran

Posted 06 December 2017 - 04:42 AM

I'm working on Yii2 advanced application project and I have a problem with yii2 built-in Error Handler. Here is description of my problem:

I have set errorAction in my backend configuration in this way:

'errorHandler' => [
    'errorAction' => 'site/error',
],


Now, the method actionError() in the SiteController catches every application exceptions, user defined exceptions and also fatal errors, except database related exception such as yii\db\IntegrityException. I don't know why, but when such an exception occurs, actionError() does not do anything! I don't want to catch exception manually with try-catch block and I want the central ErrorHandler catches all exception.

How can I fix this problem? Thank you all specially yii experts for paying attention. Please help me to solve this strange problem.
0

#2 User is offline   Ziggi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 166
  • Joined: 14-August 12

Posted 06 December 2017 - 05:32 AM

View Posthamed1991, on 06 December 2017 - 04:42 AM, said:

I don't know why, but when such an exception occurs, actionError() does not do anything


So, how do you know there was an error, actually - what is the behavior of an application?
0

#3 User is offline   hamed1991 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 20-March 14
  • Location:Iran

Posted 06 December 2017 - 05:55 AM

View PostZiggi, on 06 December 2017 - 05:32 AM, said:

So, how do you know there was an error, actually - what is the behavior of an application?


Default error page of application with stacktrace. I want to actionError() method catch the exception
0

#4 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,481
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 06 December 2017 - 06:37 AM

I know you said you don't want to catch the exception locally, but I would say you should catch it and throw an exception that can be caught by errorHandler.

Edit: I don't know if you know what was the purpose to implement an IntegrityException basically the idea is to avoid row check against database if it throws you can catch and retry or abort.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users