- PHP 4 applications mostly
- Try to mimic exceptions
- Well known through the PEAR project
- http://pear.php.net
<?php
function writeToFile( $file, $content )
{
if ( ( $f = fopen( $file, "w" ) ) === false )
{
return PEAR::raiseError(
"File not writeable",
23,
PEAR_ERROR_RETURN,
$file
);
}
// ...
}
if ( PEAR::isError(
$err = writeToFile( "/tmp/foo", "99 klingons..." )
) )
{
// handle error...
}
?>
<?php
PEAR::setErrorHandling(
PEAR_ERROR_CALLBACK,
"handleError"
);
function handleError( $err )
{
// handle error...
}
writeToFile( "/tmp/foo" );
?>