how you handle errors ?
Moderator: General Moderators
how you handle errors ?
I am thinking to use exception in my application and i taught to make error handler in index.php file string set_exception_handler ( string exception_handler) setting some function handle exceptions which prints some output to user and sends report to admin. I use exception only in critical cases like when DB hasn't made connection or some necessary files are missing. So how you handle erros or exceptions ?
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Re: how you handle errors ?
It's highly context dependent, and often the client dictates what error handling policy should be. A safe approach is to politely inform the user that an error occured, and log the details. Emailing the admin can be a little risky, since errors tend to occur in clusters.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: how you handle errors ?
And if anyone finds out and doesn't like you -- they can deliberately invoke errors and flood your inbox.Ambush Commander wrote:Emailing the admin can be a little risky, since errors tend to occur in clusters
Re: how you handle errors ?
yes that's true but have you made whole application by using only exceptions?
Re: how you handle errors ?
I have.staar2 wrote:yes that's true but have you made whole application by using only exceptions?
For the more "important" errors lets say system_exceptions
Code: Select all
<?php
class System_Exception extends Exception {
const ERR_SQL_FAILURE = 1;
const ERR_FILE_NOT_FOUND = 2;
public function __construct($exception) {
$this->code = $exception;
}
}
try {
if(file_exists('config.php')) {
include('config.php');
} else {
throw new System_Exception(System_Exception::ERR_FILE_NOT_FOUND);
}
$name = 'foo';
if($name != 'bar') {
throw new Exception('Username was invalid!');
}
} catch(System_Exception $e) {
// Handle error here maybe needs to be logged.
} catch(Exception $e) {
// Maybe use this function to display a error page?
// To retrive the error message passed to the parameter
$message = $e->getMessage();
}
?>