@ 2013-09-20T21:29:29Z <?php
class Exception
{
protected $message = 'Unknown exception'; // exception message
private $string; // __toString cache
protected $code = 0; // user defined exception code
protected $file; // source filename of exception
protected $line; // source line of exception
private $trace; // backtrace
private $previous; // previous exception if nested
public function __construct($message = null, $code = 0, Exception $previous = null)
// make sure everything is assigned properly
self::__construct($message, $code, $previous);
}
// Overrideable;
}
// Overrideable
class MyException extends Exception{
public function __construct($message, $code = 0, Exception $previous = null) {
// some code
// make sure everything is assigned properly
parent::__construct($message, $code, $previous);
}
// custom string representation of object
public function __toString() {
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}
public function customFunction() {
echo "A custom function for this type of exception\n";
}
}
class TestException
{
public $var;
const THROW_NONE = 0;
const THROW_CUSTOM = 1;
const THROW_DEFAULT = 2;
function __construct($avalue = self::THROW_NONE) {
switch ($avalue) {
case self::THROW_CUSTOM:
// throw custom exception
throw new MyException('1 is an invalid parameter', 5);
break;
case self::THROW_DEFAULT:
// throw default one.
throw new Exception('2 is not allowed as a parameter', 6);
break;
default:
// No exception, object will be created.
$this->var = $avalue;
break;
}
}
}
// Example 1
try {
$o = new TestException(TestException::THROW_CUSTOM);
} catch (MyException $e) { // Will be caught
echo "Caught my exception\n", $e;
$e->customFunction();
} catch (Exception $e) { // Skipped
echo "Caught Default Exception\n", $e;
}
// Continue execution
var_dump($o); // Null
echo "\n\n";
// Example 2
try {
$o = new TestException(TestException::THROW_DEFAULT);
} catch (MyException $e) { // Doesn't match this type
echo "Caught my exception\n", $e;
$e->customFunction();
} catch (Exception $e) { // Will be caught
echo "Caught Default Exception\n", $e;
}
// Continue execution
var_dump($o); // Null
echo "\n\n";
try {
$o = new TestException(TestException::THROW_CUSTOM);
} catch (Exception $e) { // Will be caught
echo "Default Exception caught\n", $e;
}
// Continue execution
var_dump($o); // Null
echo "\n\n";
// Example 4
try {
$o = new TestException();
} catch (Exception $e) { // Skipped, no exception
echo "Default Exception caught\n", $e;
}
// Continue execution
var_dump($o); // TestException?>
echo "p\n\n";
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.20 0.177 0.033 19.16 5.4.19 0.180 0.040 18.96 5.4.18 0.173 0.033 18.98 5.4.17 0.173 0.037 19.15 5.4.16 0.177 0.033 19.13 5.4.15 0.163 0.037 19.07 5.4.14 0.000 0.040 16.29 5.4.13 0.007 0.030 16.49 5.4.12 0.003 0.047 16.39 5.4.11 0.097 0.033 16.28 5.4.10 0.167 0.030 16.56 5.4.9 0.167 0.033 16.65 5.4.8 0.227 0.050 16.39 5.4.7 0.060 0.037 16.36 5.4.6 0.003 0.063 16.52 5.4.5 0.007 0.043 16.54 5.4.4 0.027 0.050 16.54 5.4.3 0.187 0.053 16.52 5.4.2 0.183 0.033 16.22 5.4.1 0.210 0.043 16.34 5.4.0 0.207 0.037 15.78 5.3.27 0.253 0.033 14.60 5.3.26 0.213 0.043 14.52 5.3.25 0.183 0.040 14.58 5.3.24 0.203 0.043 14.54 5.3.23 0.200 0.037 14.62 5.3.22 0.210 0.040 14.80 5.3.21 0.213 0.033 14.66 5.3.20 0.217 0.033 14.63 5.3.19 0.187 0.040 14.50 5.3.18 0.220 0.043 14.71 5.3.17 0.207 0.047 14.49 5.3.16 0.210 0.037 14.54 5.3.15 0.197 0.040 14.72 5.3.14 0.183 0.037 14.57 5.3.13 0.107 0.037 14.54 5.3.12 0.017 0.060 14.52 5.3.11 0.007 0.037 14.64 5.3.10 0.213 0.047 14.02 5.3.9 0.210 0.047 14.03 5.3.8 0.207 0.043 13.95 5.3.7 0.197 0.043 14.16 5.3.6 0.227 0.033 13.91 5.3.5 0.197 0.030 13.86 5.3.4 0.193 0.037 13.85 5.3.3 0.223 0.043 13.82 5.3.2 0.103 0.040 13.71 5.3.1 0.003 0.040 13.73 5.3.0 0.007 0.040 13.72
preferences:dark mode live preview
143.34 ms | 1394 KiB | 7 Q