Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 200 | Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of Psy Shell.
5
 *
6
 * (c) 2012-2022 Justin Hileman
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Psy\Exception;
13
 
14
/**
15
 * A throw-up exception, used for throwing an exception out of the Psy Shell.
16
 */
17
class ThrowUpException extends \Exception implements Exception
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function __construct(\Throwable $throwable)
23
    {
24
        $message = \sprintf("Throwing %s with message '%s'", \get_class($throwable), $throwable->getMessage());
25
        parent::__construct($message, $throwable->getCode(), $throwable);
26
    }
27
 
28
    /**
29
     * Return a raw (unformatted) version of the error message.
30
     *
31
     * @return string
32
     */
33
    public function getRawMessage(): string
34
    {
35
        return $this->getPrevious()->getMessage();
36
    }
37
 
38
    /**
39
     * Create a ThrowUpException from a Throwable.
40
     *
41
     * @deprecated psySH no longer wraps Throwables
42
     *
43
     * @param \Throwable $throwable
44
     *
45
     * @return self
46
     */
47
    public static function fromThrowable($throwable): self
48
    {
49
        if ($throwable instanceof \Error) {
50
            $throwable = ErrorException::fromError($throwable);
51
        }
52
 
53
        if (!$throwable instanceof \Exception) {
54
            throw new \InvalidArgumentException('throw-up can only throw Exceptions and Errors');
55
        }
56
 
57
        return new self($throwable);
58
    }
59
}