3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('log_errors','off'); // log_errors_max_len = infinite length ini_set("log_errors_max_len",0); function long_exception_handler($exception) { // for compatibility, call __toString echo $exception->__toString(); } set_exception_handler('long_exception_handler'); /** * NewException * Extends the Exception class so that the $message parameter is now mendatory. * */ class NewException extends Exception { //$message is now not optional, just for the extension. public function __construct($message, $code = 0, Exception $previous = null) { parent::__construct($message, $code, $previous); } } /** * TestException * Tests and throws Exceptions. */ class TestException { const NONE = 0; const NORMAL = 1; const CUSTOM = 2; public function __construct($type = self::NONE) { switch ($type) { case 1: throw new Exception('Normal Exception'); break; case 2: throw new NewException('Custom Exception'); break; default: return 0; //No exception is thrown. } } } try { $t = new TestException(TestException::CUSTOM); } catch (Exception $e) { print_r($e); //Exception Caught } ?>

preferences:
31.84 ms | 402 KiB | 5 Q