Results 1 to 5 of 5

Thread: Error Trapping

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Error Trapping

    Is there a way to trap errors and do certain things based on what error is received?

    Say, if I get a "Function not defined error" can I, instead of it displaying the error message, have it go to a main function?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    I did this on one of my recent projects (this works well with sql statements, and I think you can use it for other functions too:

    PHP Code:
    function ErrorHandling($type,$message) {
      echo 
    "Type: $type<br />Message: $message";
    }

    $query mysql_query("select * from table") or die(ErrorHandling("MySQL Query",mysql_error()); 
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Great idea! But why doesn't this work?:

    PHP Code:
      eval($_REQUEST["action"] . "();") or die(eval_error()); 
    It prints the normal thing and prints the eval_error() function.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    From php.net
    A return statement will terminate the evaluation of the string immediately. In PHP 4, eval() returns FALSE unless return() is called in the evaluated code, in which case the value passed to return() is returned. In PHP 3, eval() does not return a value.
    That is why.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  5. #5

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I think what I'm doing is bad anyways, so I ditched the idea.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width