SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What techniques do you use for error handling in PHP?

    I've been reading up on error handling in PHP recently. Previously, my error handling consisted of calling a function caleld custom_die() whenever something went wrong. My function would display a nicely formatted error message (you send some text describing the error as part of the function call) and terminate the script - it could also optionally mail me the details of the error or dump it in a log file.

    This aproach is far from elegant, and for my next project I want to take a far more sophisticated aproach to error handling. Unfortunately I have no idea how to go about it... Exception handling (as seen in Java and Python among others) would be ideal but PHP doesn't seem to have anything like that (which is a great shame, exception handling would make an excellent feature of the language in my opinion). PEAR seems to have an error handling mechanism which I can't quite figure out - has anyone used PEAR error handling for anything?

    PHP also has a load of strange error handling functions built in, allowing you to do things like set a callback function for when an error occurs. ARe there any disadvantages to this approach?

  2. #2
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't there a error report setting in php.ini that allows you to recieve all errors via e-mail, plus it hides the error messages from the user?

    Wait...i think it just logs the errors to a txt file and hides the errors from the user.
    Last edited by Robo; Feb 13, 2002 at 21:41.

  3. #3
    SitePoint Member
    Join Date
    Feb 2002
    Location
    Lisbon, Portugal
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    I went through the same issue, but I lack the time to complete it. Never the less, I was thinking in some kind of event system, with event handlers (sort of).
    Using a database, we could define Errors and chose what actions to take for each error. For example :
    Error [DB0034] ( Unable to find table XXX ) , for this error, we migh want to send an email to the webmaster, sms, whatever. We might also want to store it in some sort of log, and btw let the web-user to be informed about this error in some nice way like "Not now, go away!! ) .
    We could extend this to other things, imagine a web site that handles orders, and that is in contact with a company's inventory list. We might find that there are too much orders for the current stock, and issue a warning to someone.
    This is what I thought. A form to handle generic events/errors, that would be configured outside the site,intranet app, PHP-GTK, whatever application, using a database . The only event that would have to be handled outside this system, is the Database not beeing connected, but hey, it isn't perfect .
    Hummmmm to conclude , inside the site code, we would only have to find a way to issue the warnings, something like :
    if (!query) IssueEvent("DB0034",mysql_error() ) , or something like that ..

    Anyway, my 2 cents , if it's something worth debating, let's go for it if it's a bad idea all together... well, it's my first post

    ----------------
    David Ramalho
    BlackOrange
    ----------------


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •