@ 2013-09-26T17:29:45Z <?php
class Exception
{
protected $message = 'Unknown exception';
private $string;
protected $code = 0;
protected $file;
protected $line;
private $trace;
private $previous;
function __construct($message = null, $code = 0, Exception $previous = null)
final public string getMessage ( void );
final public Exception getPrevious ( void );
final public mixed getCode ( void );
final public string getFile ( void );
final public int getLine ( void );
final public array getTrace ( void );
final public string getTraceAsString ( void );
public string __toString ( void );
final private void __clone ( void );
}
/**
* Define a custom exception class
*/
class MyException extends Exception
{
// Redefine the exception so message isn't optional
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";
// Example 3
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 "\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.017 0.063 18.92 5.4.19 0.000 0.047 18.86 5.4.18 0.010 0.070 19.00 5.4.17 0.007 0.060 18.83 5.4.16 0.010 0.060 19.22 5.4.15 0.010 0.037 19.12 5.4.14 0.000 0.083 16.50 5.4.13 0.010 0.070 16.39 5.4.12 0.010 0.067 16.37 5.4.11 0.003 0.080 16.45 5.4.10 0.007 0.073 16.36 5.4.9 0.010 0.073 16.30 5.4.8 0.013 0.070 16.41 5.4.7 0.007 0.070 16.37 5.4.6 0.010 0.030 16.28 5.4.5 0.007 0.033 16.50 5.4.4 0.013 0.057 16.44 5.4.3 0.003 0.037 16.64 5.4.2 0.010 0.053 16.50 5.4.1 0.003 0.080 16.44 5.4.0 0.007 0.063 15.91 5.3.27 0.003 0.040 14.61 5.3.26 0.013 0.080 14.62 5.3.25 0.000 0.077 14.53 5.3.24 0.010 0.070 14.62 5.3.23 0.010 0.080 14.64 5.3.22 0.010 0.067 14.57 5.3.21 0.007 0.057 14.63 5.3.20 0.003 0.070 14.71 5.3.19 0.003 0.077 14.59 5.3.18 0.003 0.053 14.62 5.3.17 0.013 0.070 14.60 5.3.16 0.000 0.040 14.62 5.3.15 0.007 0.067 14.63 5.3.14 0.007 0.033 14.59 5.3.13 0.007 0.037 14.71 5.3.12 0.017 0.063 14.61 5.3.11 0.003 0.063 14.60 5.3.10 0.007 0.050 14.07 5.3.9 0.010 0.030 13.94 5.3.8 0.000 0.077 13.93 5.3.7 0.007 0.043 14.07 5.3.6 0.007 0.047 14.06 5.3.5 0.003 0.043 13.91 5.3.4 0.003 0.037 13.98 5.3.3 0.003 0.037 13.91 5.3.2 0.003 0.060 13.58 5.3.1 0.000 0.043 13.66 5.3.0 0.003 0.037 13.63
preferences:dark mode live preview
143.21 ms | 1398 KiB | 8 Q