For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > September 2006 > Making my own warnings









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Making my own warnings
Jean Pierre Daviau

2006-09-22, 6:57 pm

Hi guus,

Can I transform a normal warning (Warning: Division by zero in C:\Documents
and Settings\Jean Pierre\Bureau\learnphp\arc.php on line 92) in an exception
or a fatal error to stop the process and exit a program or application?



--
Thanks for your attention.

Jean Pierre Daviau
--
Easyphp1.8 with Apache1.3.24
Server version: Apache/2.0.55
Server built: Oct 9 2005 19:16:56
DEVC++, borland 5.5
windows Xp
asus p4 s533/333/133
Intel(R) Celeron (R) CPU 2.00 GHz
Processor Radeon7000 0x5159 agp
http://www.jeanpierredaviau.com


Juliette

2006-09-23, 6:57 pm

Jean Pierre Daviau wrote:
> Hi guus,
>
> Can I transform a normal warning (Warning: Division by zero in C:\Documents
> and Settings\Jean Pierre\Bureau\learnphp\arc.php on line 92) in an exception
> or a fatal error to stop the process and exit a program or application?
>
>
>



Yes



Test the values before doing the action which may cause the warning, if
the test shows that one of the values if 0, use trigger_error with
E_USER_ERROR
Jean Pierre Daviau

2006-09-24, 6:57 pm


> Test the values before doing the action which may cause the warning, if
> the test shows that one of the values if 0, use trigger_error with
> E_USER_ERROR



Your my Juliet




Romeo ;-)


Jean Pierre Daviau

2006-09-24, 6:57 pm

In php 5

<?

//Parse error: parse error, unexpected T_CATCH, expecting T_STRING in
C:\Documents and Settings\Jean Pierre\Bureau\learnphp\delme.php on line 2

function catch ($errno, $errstr, $errfile, $errline){
$GLOBALS['throw'] = $errstr;
$GLOBALS['throw_info'] = array(
'Message'=>$errstr
,'Code'=>$errno
,'Line'=>$errline
,'File'=>$errfile
,'Trace'=>debug_backtrace()
);
}


function badgirl(){
trigger_error("BadGirlWithError", E_USER_NOTICE); // as throw with notice
}

set_error_handler('catch');
badgirl();
?>


TheQuim

2006-09-25, 7:58 am

Jean Pierre Daviau wrote:
> Hi guus,
>
> Can I transform a normal warning (Warning: Division by zero in C:\Documents
> and Settings\Jean Pierre\Bureau\learnphp\arc.php on line 92) in an exception
> or a fatal error to stop the process and exit a program or application?
>
>
>

Jean Pierre,

You better off writing a custom error handler for errors of this nature.


For example (Just FYI)

function errorHandle($errMsg){


return "<p>Warning : An error has occured</p><p>Error Messsage : $errMsg ";
}


That is a very weak handler but all you now need to do is check for the
number that you are dividing by and see if it is equal to 0, if it is
kick into the handler by calling die(errorHandle($errMsg)) and display
whatever error message you would like and stopping all execution from
that point on.

I hope this helps


Regards

Q.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com