The issue: Exceptions are needed for error handling
<?php
class CouldNotConnectException extends exception {
public function __construct( $server ) {
parent::__construct( "Could not connect to server <$server>." );
}
}
class ExceptionExample {
public function connectToServer( $server ) {
if ( !($c = @fsockopen( $server, 80, $errno, $errstr, 0.1 ) ) ) {
throw new CouldNotConnectException( $server );
}
}
}
$object = new ExceptionExample();
try {
$object->connectToServer( 'unavailable' );
} catch ( CouldNotConnectException $e ) {
echo 'Cought: ', $e, "\n";
} catch ( Exception $e ) {
// Cought another exception
}
?>
Output
Cought: CouldNotConnectException: Could not connect to server . in /local/Web/sites/talks.php.net/display.php(573) : eval()'d code:12
Stack trace:
#0 /local/Web/sites/talks.php.net/display.php(573) : eval()'d code(20): ExceptionExample->connectToServer()
#1 /local/Web/sites/talks.php.net/display.php(573): eval()
#2 /local/Web/sites/talks.php.net/objects.php(128): html->_example()
#3 /local/Web/sites/talks.php.net/display.php(92): _tag->display()
#4 /local/Web/sites/talks.php.net/objects.php(128): html->_presentation()
#5 /local/Web/sites/talks.php.net/show.php(122): _tag->display()
#6 {main}
Exceptions bubble through your code until catched.
Exceptions result in a Fatal Error, if not catched properly.