Try...Catch
Moderator: General Moderators
Try...Catch
Does PHP 4 or 5 have the try and catch statements built in?
you might talk to d11wtq. Here is a hackaround (his word) he came up with for his Swift library:
http://swiftmailer.org/wikidocs/v3/misc/php4errors
http://swiftmailer.org/wikidocs/v3/misc/php4errors
I guess with a statement with an include() function I could do:
Code: Select all
inlcude($something) || die("Error");
One way to emulate try/catch is to use a switch. You have to add additional code to customize the behavior you want.
Code: Select all
switch (null)
{
default:
if ($x === false)
{
$error = 'blah';
break;
}
}
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Believe me, I've had all the headaches on this and tried numerous workarounds. It's just not doable. There's no way PHP4 will ever reach that level of bubbling that try/catch provides. The beauty of exceptions is that the exception my be thrown at a very low level where you're not able to monitor it, but execution will still jump directly from your try to your catch block.
I'd suggest using trigger_error() and set_error_handler() but it's in no way shape or form the same.
It really depends on how you use exceptions. Exceptions provide two things:
* Error messages
* Program flow
The latter is where PHP4 falls flat on its face.
I'd suggest using trigger_error() and set_error_handler() but it's in no way shape or form the same.
It really depends on how you use exceptions. Exceptions provide two things:
* Error messages
* Program flow
The latter is where PHP4 falls flat on its face.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia