Re: Simple error handling/catching/avoidance
"Jacob Kruger" <[email protected]>
| Newsgroups | gmane.comp.php.windows |
|---|---|
| Message-ID | <EE690CAF001E4EACB23BC8DAA4FCDC2E@jakesPC> |
Ok, thanks - now that php.net is back online, that page sorted out a form of
solution - check out this relatively simple source code:
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");
$iVar1 = 10;
$iVar2 = 0;
try {
$iVar1 = $iVar1 / $iVar2;
} catch (Exception $e) {
$iVar1 = 100;
}
//continue
echo $iVar1;
?>
Stay well
Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'
----- Original Message -----
From: "Toby Hart Dyke" <[email protected]>
To: "'Keith Davis'" <[email protected]>; "'Jacob Kruger'"
<[email protected]>; <[email protected]>
Cc: <[email protected]>
Sent: Friday, June 08, 2012 4:40 PM
Subject: RE: [PHP-WIN] Simple error handling/catching/avoidance
>
> The problem is noted here
> (http://www.php.net/manual/en/language.exceptions.php):
>
>>Internal PHP functions mainly use Error reporting, only modern Object
> oriented extensions use exceptions. However, errors can be simply
> translated
> to exceptions with >ErrorException.
>
> One possible solution (noted here:
> http://www.php.net/manual/en/class.errorexception.php) is to add this at
> the
> beginning of your code:
>
> function exception_error_handler($errno, $errstr, $errfile, $errline )
> {
> throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
> }
> set_error_handler("exception_error_handler");
>
> That will catch your divide by zero error.
>
> Toby
>
>
> -----Original Message-----
> From: Keith Davis [mailto:[email protected]]
> Sent: Friday, June 08, 2012 10:29 AM
> To: Jacob Kruger; [email protected]
> Cc: [email protected]
> Subject: RE: [PHP-WIN] Simple error handling/catching/avoidance
>
> Oh, I agree and working with C# makes me really understand how limited the
> PHP exception / error handling process is.
>
> Keith Davis (214) 906-5183
>
>
> -----Original Message-----
> From: Jacob Kruger [mailto:[email protected]]
> Sent: Friday, June 08, 2012 8:39 AM
> To: [email protected]
> Cc: [email protected]
> Subject: Re: [PHP-WIN] Simple error handling/catching/avoidance
>
> Yup.
>
> That bit of obvious error-generating code was also just an example of
> something that would definitely generate an error/exception, since current
> actual issue is that am meant to be using/operating within someone else's
> sort of containing framework/wrappers, and means can't always be sure what
> code will work, or generate an error, etc., and just don't want to have to
> specifically check for all function definitions using function_exists(),
> etc. etc., but anyway.
>
> Also just that, in most other languages, there is some or other,
> relatively
> simple way to handle something like a try - catch exception - and just
> perform some other action methodology, so was just wondering...?
>
> Stay well
>
> Jacob Kruger
> Blind Biker
> Skype: BlindZA
> '...fate had broken his body, but not his spirit...'
>
> ----- Original Message -----
> From: "Keith Davis" <[email protected]>
> To: "Jacob Kruger" <[email protected]>
> Cc: <[email protected]>
> Sent: Friday, June 08, 2012 3:20 PM
> Subject: Re: [PHP-WIN] Simple error handling/catching/avoidance
>
>
> It's the reason why I can't stand exceptions in PHP, we talked about this
> a
> bunch at our meeting on Wednesday.
>
> You still have to suppress the error through one of several methods (using
> @
> or custom error handler that does not display it)
>
> AND then you have to throw an exception manually.
>
> I fact, I don't even know how you would write one for that type of error.
> Live to hear some more input.
>
>
> Sent from my iPhone 4s
>
> On Jun 8, 2012, at 6:30 AM, "Jacob Kruger" <[email protected]> wrote:
>
>> Just wondering why the following code actually renders an error
> message
>> instead of just then invoking the catch clause:
>>
>> //start code
>> $iVar1 = 0;
>> $iVar2 = 10;
>> try {
>> echo $iVar2 / $iVar1;
>> } catch (Exception $e) {
>> echo "No division by zero allowed";
>> }
>> //end of code
>>
>> Stay well
>>
>> Jacob Kruger
>> Blind Biker
>> Skype: BlindZA
>> '...fate had broken his body, but not his spirit...'
>
>
> This message (including any attachments) may contain confidential or
> otherwise privileged information and is intended only for the
> individual(s)
> to which it is addressed. If you are not the named addressee you should
> not
> disseminate, distribute or copy this e-mail. Please notify the sender
> immediately by e-mail if you have received this e-mail by mistake and
> delete
> this e-mail from your system. E-mail transmission cannot be guaranteed to
> be
> secured or error-free as information could be intercepted, corrupted,
> lost,
> destroyed, arrive late or incomplete, or contain viruses. The sender
> therefore does not accept liability for any errors or omissions in the
> contents of this message or that arise as a result of e-mail transmission.
> If verification is required please request a hard-copy version from the
> sender.
>
> www.pridedallas.com
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php