Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 8th, 2008, 03:25 PM
703designs
Guest
 
Posts: n/a
Default Error Handlers

How can I add a a row for every error? I know I did this before, but
lost the code. The reason that this is necessary: I want errors to
build into a table which is positioned absolutely (bottom: 1em; left:
1em). I can only have one copy of the table, otherwise errors overlap
each other.

What I have now doesn't work, and I'm not entirely sure why (I know
it's crappy code, but error handling is a black box indeed, plus this
is for a prototype CSS framework, so I'm not being picky):

http://pastebin.com/m29c58d92
  #2  
Old October 8th, 2008, 04:15 PM
=?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=
Guest
 
Posts: n/a
Default Re: Error Handlers

703designs escribió:
Quote:
How can I add a a row for every error? I know I did this before, but
lost the code. The reason that this is necessary: I want errors to
build into a table which is positioned absolutely (bottom: 1em; left:
1em). I can only have one copy of the table, otherwise errors overlap
each other.
Quote:
<?php
$errors = "<table class='phpError'>"
. "<tr><th>Level</th><th>Error</th><th>File</th><th>Line</th></tr>";
$errorCount = 0;
>
function golondrinaErrors($number, $string, $file, $line) {
global $errors;
global $errorCount;
$errorCount++;
$errors .= "<tr><td>" . $number . "</td>"
. "<td>" . $string . "</td>"
. "<td>" . $file . "</td>"
. "<td>" . $line . "</td>"
. "</tr>";
return true;
}
if($errorCount 0) {
$errors .= "</table>";
echo $errors;
}
>
set_error_handler('golondrinaErrors');

What this code seems to do is:

1. Set error count to zero
2. Print errors if error count is greater than zero
3. Tell PHP to user your custom error handler
4. Increase the error count when new errors found

You'd need to move the "print errors" part to the end of your script so
it has the chance of catching some errors before printing them.

Also, be aware that your error handler doesn't honor the @ operator and
it never aborts the script no matter the error type (might be what you
want or not).


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
  #3  
Old October 8th, 2008, 05:05 PM
703designs
Guest
 
Posts: n/a
Default Re: Error Handlers

Thanks Alvaro, that makes perfect sense. This is for only my own use,
mainly to catch missed includes (for wireframing), but I'll certainly
look into making it @-safe, which seems like an interesting topic to
me.

Thomas

On Oct 8, 11:05*am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
Quote:
703designs escribió:
>
>
>
Quote:
How can I add a a row for every error? I know I did this before, but
lost the code. The reason that this is necessary: I want errors to
build into a table which is positioned absolutely (bottom: 1em; left:
1em). I can only have one copy of the table, otherwise errors overlap
each other.
<?php
$errors = "<table class='phpError'>"
* * . "<tr><th>Level</th><th>Error</th><th>File</th><th>Line</th></tr>";
$errorCount = 0;
>
Quote:
function golondrinaErrors($number, $string, $file, $line) {
* * global $errors;
* * global $errorCount;
* * $errorCount++;
* * $errors .= *"<tr><td>" . $number . "</td>"
* * * * . "<td>" . $string . "</td>"
* * * * . "<td>" . $file . "</td>"
* * * * . "<td>" . $line . "</td>"
* * * * . "</tr>";
* * return true;
}
if($errorCount 0) {
* * $errors .= "</table>";
* * echo $errors;
}
>
Quote:
set_error_handler('golondrinaErrors');
>
What this code seems to do is:
>
1. Set error count to zero
2. Print errors if error count is greater than zero
3. Tell PHP to user your custom error handler
4. Increase the error count when new errors found
>
You'd need to move the "print errors" part to the end of your script so
it has the chance of catching some errors before printing them.
>
Also, be aware that your error handler doesn't honor the @ operator and
it never aborts the script no matter the error type (might be what you
want or not).
>
--
--http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles