Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | 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
 *
200 lars 6
 * (c) 2012-2023 Justin Hileman
148 lars 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
    public function getRawMessage(): string
32
    {
33
        return $this->getPrevious()->getMessage();
34
    }
35
 
36
    /**
37
     * Create a ThrowUpException from a Throwable.
38
     *
39
     * @deprecated psySH no longer wraps Throwables
40
     *
41
     * @param \Throwable $throwable
42
     */
43
    public static function fromThrowable($throwable): self
44
    {
45
        if ($throwable instanceof \Error) {
46
            $throwable = ErrorException::fromError($throwable);
47
        }
48
 
49
        if (!$throwable instanceof \Exception) {
50
            throw new \InvalidArgumentException('throw-up can only throw Exceptions and Errors');
51
        }
52
 
53
        return new self($throwable);
54
    }
55
}