Jump to content

Recommended Posts

Hello,

 

    I have a question about my messaging / error logging system.  I am working on a data-crunching script, so it doesn't get viewed as a public web page, it only is seen by the administrator.  All it needs is a simple on-screen output tape that keeps the person who is running it up to date on how it is working.

    So, lots of non-error status messages get written to the screen, and also into a log file and a log database-table.  I'd like to make a clean, standard way for handling all these messages.  I considered making my own "message" object that would contain a text message describing the error, an "importance" code, a message type ("error", "info", or "debug"), and a debug trace.

    So here's my question:  the built in Exception class has almost all that stuff already, and I could extend it.  Could I use exceptions for non-error messages?  Would that be good practice?  It would look like this:

 

$m = new ExeptionMessage('normal operation...50% done', 2, 'info');
$myMessageLoggingObject->send($m);

 

this would be slick: I wouldn't need to make my own message object, and I could swap-in normal, ordinary, thrown exceptions into my ->send() function,

and they would work just fine! 

 

catch (Exception $e) {
    $myMessageLoggingObject->send($e);
}

 

Is there any problems you could see with this?  Is it bad practice to use Exceptions when they are not being thrown?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/186709-message-system/
Share on other sites

  • 2 weeks later...
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.