user2054381
user2054381

Reputation:

Make yii 1.1 contunie working with non noncritical errors

Working with yii 1.1 sometimes I find in very ungood that on any error(even on noncritical like Undefined variable ) in my code the working of my app is stopped and error page is shown and also all output of my site is not visible. If there is a way to continue rendering of page with noncritical errors ? Maybe using xdebug_start_error_collection and xdebug_get_collected_errors methods from here http://www.xdebug.org/docs/basic ?

Upvotes: 1

Views: 60

Answers (1)

crafter
crafter

Reputation: 6296

The ability to do this is related more to the capabilities and features of PHP than Yii.

On the outset I want to warn that this is not a good idea, because sometimes errors encountered may have an effect on what happens next. (Think for example being able to complete an order even after an attempt to read the customer record returned an error.)

The correct way is to handle all possible outcomes in your code.

To be able to catch unexpected errors, use the try{} catch{} mechanism of PHP.

try {
   something_to_do();
}
catch($e){
   handle_some_error();
}

continue_processing();

However, if you want to proceed along your intented line, have a look at the error handling capabilities of PHP, in particular : http://php.net/manual/en/function.set-error-handler.php

In particular, one good technique is to create an error handler, as in the code below.

function HandleErrors() {
  $errorDetails = error_get_last();

  $ignoreSettings = E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED;

  print_r($errorDetails);
  print_r($ignoreSettings);
  if (($errorDetails['type'] & $ignoreSettings) == 0) {
     do_things_to_handle_the_error;
  }
}

register_shutdown_function('HandleErrors');

Upvotes: 1

Related Questions