4 * This file is part of Psy Shell.
6 * (c) 2012-2017 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Psy\Exception;
15 * A custom error Exception for Psy with a formatted $message.
17 class ErrorException extends \ErrorException implements Exception
22 * Construct a Psy ErrorException.
24 * @param string $message (default: "")
25 * @param int $code (default: 0)
26 * @param int $severity (default: 1)
27 * @param string $filename (default: null)
28 * @param int $lineno (default: null)
29 * @param Exception $previous (default: null)
31 public function __construct($message = '', $code = 0, $severity = 1, $filename = null, $lineno = null, $previous = null)
33 $this->rawMessage = $message;
35 if (!empty($filename) && preg_match('{Psy[/\\\\]ExecutionLoop}', $filename)) {
42 case E_COMPILE_WARNING:
48 $type = 'Strict error';
56 $message = sprintf('PHP %s: %s%s on line %d', $type, $message, $filename ? ' in ' . $filename : '', $lineno);
57 parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
61 * Get the raw (unformatted) message for this error.
65 public function getRawMessage()
67 return $this->rawMessage;
71 * Helper for throwing an ErrorException.
75 * set_error_handler(array('Psy\Exception\ErrorException', 'throwException'));
77 * @throws ErrorException
79 * @param int $errno Error type
80 * @param string $errstr Message
81 * @param string $errfile Filename
82 * @param int $errline Line number
84 public static function throwException($errno, $errstr, $errfile, $errline)
86 throw new self($errstr, 0, $errno, $errfile, $errline);
90 * Create an ErrorException from an Error.
94 * @return ErrorException
96 public static function fromError(\Error $e)
98 return new self($e->getMessage(), $e->getCode(), 1, $e->getFile(), $e->getLine(), $e);