Page 1 of 1

how to handle exceptions in php4(please give example also)

Posted: Fri Dec 30, 2005 4:41 pm
by rajan
how to handle exceptions in class just by creating the instance on php4. please give me answer with some coding examples.

Posted: Fri Dec 30, 2005 4:47 pm
by foobar
To quote myself from this thread:
foobar wrote: There is no exception handling in PHP4.
Also, I think I explained the alternatives in said thread pretty well. Might want to get back to it.

Posted: Fri Dec 30, 2005 4:52 pm
by rajan
but how to handle the error in class ? how to get the error messages or u can say user generated error messages from inside class?

Posted: Fri Dec 30, 2005 8:28 pm
by Chris Corbyn
rajan wrote:but how to handle the error in class ? how to get the error messages or u can say user generated error messages from inside class?
In PHP4 you can't catch the errors.

You can surpress the output and use your own error output by using the @ syntax.

Code: Select all

if ($foo = @some_undefined_function()) echo $foo;
else echo 'WTF?? Function is undefined';
The @ simply stops the error from being displayed and simply returns false instead.

You can also log the errors to a log file rather than displaying them on screen. As ~foobar says... exception handling is new to PHP5.

Posted: Sat Dec 31, 2005 2:00 am
by Jenk

Posted: Sat Dec 31, 2005 12:34 pm
by Ambush Commander
::Agree with Jenk::

There really isn't any satisfactory way in PHP4 to catch errors: you'll probably end up bubbling them up to a caller that knows enough how to handle them.

Also, PEAR has exception emulation: you may want to take a look at that.