Jump to content

Recommended Posts

Well for a simple example you could do something like this:

 

<?php
/**
* All my Error defines
*/


// Few Options
define('DISPLAY_ERROR', true);
define('LOG_ERROR', true);
define('LOG_DB_TABLE', 'error_logs');

// Database Error Messages
define('E_DB_CONN', 'Error connecting to the database');
define('E_DB_QUERY', 'There was an error in the query');

// User Login Error Messages
define('E_USER_LOGIN', 'You have entered and invalid username or password');
define('E_USER_TIMEOUT', 'Your session has expired, please login again');

// Define my custom error levels
define(-1, 'E_DB');
define(-2, 'E_USER');


// etc...

class ErrorMsg
{
    protected $_EMSG    = NULL;
    protected $_ETYPE   = NULL;
    
    function __contrcut($errorID = 0, $errorMSG = '')
    {
        switch ($errorID) {
            case -1:
                $this->_ETYPE   = 'Database Error: ';
                $this->_EMSG    = $errorMSG;
                break;
            
            case -2:
                $this->_ETYPE   = 'User Error: ';
                $this->_EMSG    = $errorMSG;
                break;
            
            // etc...
            
            default:
                //unknow or unaccounted for error
                $this->_ETYPE   = 'Unknown Error: ';
                $this->_EMSG    = 'An unknown error occured.';
                break;
        }
        
        if (LOG_ERROR) {
            ErrorMsg::logError();
        }
        
        if (DISPLAY_ERROR) {
            ErrorMsg::displayError();
        }
        
    }
    
    function logError()
    {
        // DB Connection stuff
        
        // Exe the DB query
        $db->query("insert into " . LOG_DB_TABLE . " (error_id, error_message, error_time) VALUES ('$this->_ETYPE', '$this->_EMSG', NOW())");
        
        return true;
        
    }
    
    function displayError()
    {
        print "<strong>$this->_ETYPE</strong>: $this->_EMSG";
        
        return true;
    
    }
    
}
?>

 

Please keep in mind this is just an example i just slapped down in a few mins right in this editor, so sorry if the spacing is off etc.. and you would have to really tweek it to get it to work for you but it's an idea anyways, hopefully it will lead you down the right path.

Hi,

I am new to OOP. Can any one give / suggest me a ERROR HANDLER script and show me how to use it in other class.

 

Pls. helllllllllllllllllllllllllllllllllllllllllp !

 

Are you referring to ERRORS or actually handling Exceptions? The latter was introduced with PHP5 and is what most people are working with when it comes to OOP. A little further explanation of what you need would be helpful.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.