[TUT] Custom Error Handling ( PHP )

Discussion in 'Archives' started by Puzzle, May 7, 2007.

[TUT] Custom Error Handling ( PHP )
  1. Unread #1 - May 7, 2007 at 4:28 PM
  2. Puzzle
    Joined:
    May 6, 2005
    Posts:
    846
    Referrals:
    0
    Sythe Gold:
    0

    Puzzle Apprentice

    [TUT] Custom Error Handling ( PHP )

    Ok so everyone here would probably agree with me that PHP's default method of displaying your errors isn't very friendly at times so i thought why not tell you guys how to make your own function that does the SAME thing as the php error but in a more please able format.

    Lets get started, im assuming that everyone here has some basic php knowledge or else you shouldn't be reading this. First thing you must do is add this function somewhere on your page

    Code:
    <?php
          function errhandle($errnum, $errmsg, $errfile, $errline, $errcntxt) // only the first two parameters error number and error message must be used, the other 3 are optional.
    	    {
    		echo "<b>Error Number: $errnum<br>";
    		echo "<b>Reason: $errmsg<br>";
    		echo "<b>File: $errfile<br>";
    		echo "<b>Line: $errline<br>";
    		echo "<b>Type: $errcntxt<br><br>";
            echo "<b>Terminating Process....</b>";
    		die();
    		}
              ?>
    I recommend you add that before the doctype.

    now lets move onto actually testing it :)..

    go onto a different part of your form and add this

    Code:
    <?php
           set_error_handler("errhandle") //tells PHP to use the function instead of default error handling.
           echo $oops
    ?>
    save it as index.php or w/e you want as long as you keep .php

    the above code will generate the error saying string doesnt exist! Obviously because you havent declared it to be anything.. Anyways this concludes my tut :) be creative and remember to use this, makes your code look professional
     
< --Selling Wicked Pking Names-- | G's MMing Service >

Users viewing this thread
1 guest


 
 
Adblock breaks this site