What is a good way to manage error and success messages and codes?

I currently do not have a very good system for managing error or success messages; they are largely written with the code. Can someone suggest a best practice or something that you do to be able to properly manage a large list of error messages and successes through the app.

Think about internationalization ... some applications will have language files, and then the application simply pulls lines from a specific file ... I am thinking of implementing a similar concept for error messages and successes, and I'm curious what others did along the same lines?

+4
source share
3 answers

Here is the function I'm using:

function checkErrors($type, $msg, $file, $line, $context) { echo "<h1>Error!</h1>"; echo "An error occurred while executing this script. Please contact the <a href=mailto: webmaster@somedomain.com >webmaster</a> to report this error."; echo "<p />"; echo "Here is the information provided by the script:"; echo "<hr><pre>"; echo "Error code: $type<br />"; echo "Error message: $msg<br />"; echo "Script name and line number of error: $file:$line<br />"; $variable_state = array_pop($context); echo "Variable state when error occurred: "; print_r($variable_state); echo "</pre><hr>"; } set_error_handler('checkErrors'); 

it will give you all the errors and warnings that your PHP code creates, and also create a page with an error in case someone visits the page with an error.

Hope this helps!

+1
source

Since I use a single access style system that loads the application and includes the correct file (this is basically a controller system), I can use:

 <?php try { require 'bootstrap.php'; // dispatch controller require "controllers/$controller.php"; } catch (Exception $e) { // echo info } catch (LibraryException $le) { // library specific exception } 

Then when I want to throw an error, I just:

 throw new Exception('An error occurred.'); 

Can someone suggest a best practice or something that you do to be able to properly manage a large list of error messages and successes through the app.

This is how I manage mass errors, but not how to manage a list. I could grep for the error messages I find, but this is not very organized.

0
source

You can use something like PHP Documentor and include errors and messages in documents for each class.

http://www.phpdoc.org/

0
source

All Articles