Jump to content


Exception Handling Levels - Have a Look

  • This topic is locked This topic is locked
2 replies to this topic

Poll: How do you rate this tutorial? (5 member(s) have cast votes)

How do you rate this tutorial?

  1. Array (4 votes [100.00%])

    Percentage of vote: 100.00%


#1 shivabharat

  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 21 February 2003 - 03:29 PM

I see lot of postings in the forum related to the notices, warning and handling errors. I would like to share my views in dealing with this and I hope this helps you.

To begin with lets see what each one is all about

Notices – The names says it all, they really don’t mean anything serious just a notice for you to consider. Example undefined string.

Warnings – You ought to give a consideration to these. A warning can occur due to different reasons like trying to refer a file in your script when you don’t have one in that name.

Fatal Errors - Something to deal with immediately.

Parse Error -
When you put in something like this u get this error
<? <html> </html> ?>
The php parser will not identify HTML tags and you get a parse error.

Difference Between Error and Warning
The difference between Warning and Error is a warning will not terminate the script were as a fatal error would.

You can set the “error reporting” level in you “php.ini” file

;  - Show all errors, except for notices
;error_reporting = E_ALL & ~E_NOTICE
;  - Show only errors
;  - Show all errors except for notices
error_reporting  =  E_ALL & ~E_NOTICE

Now you feel that you don’t have rights to change the ini file, well you can tackle them in your script, now lets see how it’s done.

List of errors that occur

Error Type What do they mean?

E_ERROR --------- Fatal runtime error
E_WARNING --------- Non-fatal runtime error
E_PARSE --------- Runtime parse error
E_NOTICE --------- Non-fatal runtime notice
E_CORE_ERROR --------- Fatal startup error
E_CORE_WARNING --------- Non-fatal startup error
E_COMPILE_ERROR --------- Fatal compile-time error
E_COMPILE_WARNING --------- Non-fatal compile-time error
E_USER_ERROR --------- User-triggered fatal error
E_USER_WARNING --------- User-triggered non-fatal error
E_USER_NOTICE --------- User-triggered notice
E_ALL --------- All of the above


To avoid errors in PHP script use the error_reporting function

<? error_reporting(0); ?>

This will not report any error. Don’t use this.

<? error_reporting(E_ALL); ?>
Reports all errors

<? error_reporting(E_ERROR | E_WARNING | E_NOTICE);?>

Will show only warning, notice & errors.

<? Echo error_reporting() ?>
Will show your current error reporting level.

Hope this basic tutorial on Error Handling helped you. :lol:
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#2 Kriek

  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationFlorida

Posted 18 August 2003 - 12:05 PM

Personally, I prefer to turn off errors completely from displaying to the screen with ini_set(), then log the appropriate/significant errors to a log txt file with a combination of error_log(), set_error_handler(), and error_reporting() instead.

    function errorHandle($number, $string, $file, $line) {
        error_log("Error($number) on line $line in file $file. The error was "$string"n", 3, "errors.txt");
    ini_set('display_errors', 0);

Jon Kriek · PHP Freaks
Sometimes the need to mess with their heads ...
... outweighs the millstone of humiliation.

#3 obsidian

  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 09 July 2005 - 04:57 PM

Notices – The names says it all, they really don’t mean anything serious just a notice for you to consider. Example undefined string.

i'll have to disagree slightly with this approach. IMHO, any time you have any error of any sort, whether it be a notice or a parse error, it needs to be dealt with before you launch a site. notices are serious in the light that they are showing you areas in which your code is not up to standards. if you have a notice, you have an area of code where you are not using good coding practices. for instance, using the example given above, when you refer to a variable when it has not been declared yet, you get a notice (undefined string)... all you have to do to get rid of the notice is check to see whether the variable isset() or not. it's not hard to deal with, it just takes some time and commitment from the coder, and this is what separates the dedicated coders from the hobbyists.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users