1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FigTree\Exceptions; |
4
|
|
|
|
5
|
|
|
use Throwable; |
6
|
|
|
use RangeException as PHPRangeException; |
7
|
|
|
use FigTree\Exceptions\Concerns\HasSeverity; |
8
|
|
|
use FigTree\Exceptions\Contracts\{ |
9
|
|
|
SevereExceptionInterface, |
10
|
|
|
LocatableExceptionInterface, |
11
|
|
|
}; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Exception thrown to indicate range errors during program execution. |
15
|
|
|
* Normally this means there was an arithmetic error other than under/overflow. |
16
|
|
|
* This is the runtime version of DomainException. |
17
|
|
|
*/ |
18
|
|
|
class RangeException extends PHPRangeException implements SevereExceptionInterface, LocatableExceptionInterface |
19
|
|
|
{ |
20
|
|
|
use HasSeverity; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Exception thrown to indicate range errors during program execution. |
24
|
|
|
* Normally this means there was an arithmetic error other than under/overflow. |
25
|
|
|
* This is the runtime version of DomainException. |
26
|
|
|
* |
27
|
|
|
* @param string $message The Exception message to throw. |
28
|
|
|
* @param int $code The Exception code. |
29
|
|
|
* @param \Throwable $previous The previous throwable used for the exception chaining. |
30
|
|
|
*/ |
31
|
|
|
public function __construct(string $message = '', int $code = 0, Throwable $previous = null) |
32
|
|
|
{ |
33
|
|
|
parent::__construct($message, $code, $previous); |
34
|
|
|
|
35
|
|
|
$this->severity = E_ERROR; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* If required, set the file and line where the Exception was thrown. |
40
|
|
|
* |
41
|
|
|
* @param string $file |
42
|
|
|
* @param int $line |
43
|
|
|
* |
44
|
|
|
* @return $this |
45
|
|
|
*/ |
46
|
|
|
public function onFileLine(string $file, int $line): LocatableExceptionInterface |
47
|
|
|
{ |
48
|
|
|
if (file_exists($file)) { |
49
|
|
|
$this->file = $file; |
50
|
|
|
$this->line = max(0, $line); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|