This is a vague question, but I am wondering if you guys can offer some advice on designing a better Error-Handler?! :-/
Here is what I have now…
In each script, my Error-Handling Code looks like this…
// ************************
// Check Section Format. *
// ************************
$validSections = array("finance", "legal", "management", "small-business", "xxx");
if (in_array($_GET['section'], $validSections, FALSE)){
// Valid Section Format.
// Continue processing things...
}else{
// Invalid Section Format.
$_SESSION['resultsCode'] = 'ARTICLE_INDEX_SECTION_NOT_FOUND_2421';
// Set Error Source.
$_SESSION['errorPage'] = $_SERVER['SCRIPT_NAME'];
// Redirect to Display Outcome.
header("Location: " . BASE_URL . "/account/results.php");
// End script.
exit();
}//End of CHECK SECTION FORMAT
Then my “results.php” script does the following…
- Displays an Error Message to the User
- Logs the Error into a Database Table
- Emails the Admin if the Error could not be written to the Database
- Emails the Admin with a similar Error Message so he/she can stay informed of User/System Errors
For the Error Messages, I just use a gigantic Case statement like this…
// Invalid Section Format.
case 'ARTICLE_INDEX_SECTION_NOT_FOUND_2421':
echo '<h1>Section Not Found</h1>';
echo '<p>The Section you chose cannot be found. (2421)</p>';
echo '<a class="button" href="' . BASE_URL . '/">Return to Home Page</a>';
break;
Any thoughts or suggestions?
(BTW, I am still stuck with Procedural Code for now, so please don’t offer any OOP suggestions as that’s over my head for now?!)
Sincerely,
Debbie