-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlect1.php
More file actions
105 lines (77 loc) · 1.89 KB
/
lect1.php
File metadata and controls
105 lines (77 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Created by PhpStorm.
* User: APG
* Date: 16.05.2020
* Time: 11:33
*/
set_exception_handler(function (Throwable $e) {
echo 'Was not caught ' . $e->getMessage();
});
/*
class BadValueException extends \InvalidArgumentException
{
}
class TooBigValueException extends BadValueException
{
}
class NegativeValueException extends BadValueException {}
function arithOper($a, $b)
{
if ($a < 0 || $b < 0) {
throw new NegativeValueException('a < 0 || b < 0');
}
if ($a <= $b) {
throw new TooBigValueException('a <= b');
}
if ($b == 0) {
throw new \InvalidArgumentException('b == 0');
}
return $a / $b;
}
$values = [
['a' => 0, 'b' => 2],
['a' => -1, 'b' => -3],
['a' => 10, 'b' => 0],
['a' => 3, 'b' => 1],
];
echo "<pre>";
foreach ($values as $item) {
try {
try {
echo 'a = ' . $item['a'] . ' b = ' . $item['b'] . ' ';
$c = arithOper($item['a'], $item['b']);
echo 'Result is ' . $c . "<br>";
} catch (BadValueException $e) {
echo 'values problem ' . $e->getMessage() . PHP_EOL;
}
} catch (Exception $e) {
echo 'Log error ' . $e->getMessage() . PHP_EOL;
}
}
echo "</pre>";
echo 'THE END';
throw new Exception('Some error', 300);
echo "THE END";
*/
/*
try {
throw new RuntimeException('Error is here', 300);
echo 'Error is not came ' . PHP_EOL;
} catch (RuntimeException $e) {
echo 'Runtime error : ' . $e->getMessage() . PHP_EOL;
} catch (Exception $e) {
echo 'Error is: ' . $e->getMessage() . PHP_EOL;
} finally {
echo 'The line is always ' . PHP_EOL;
}
echo 'THE END';
try {
throw new Exception('Error is here', 300);
echo 'Error is not came ' . PHP_EOL;
} catch (Exception $e) {
echo 'Error is: ' . $e->getMessage() . PHP_EOL;
} finally {
echo 'The line is always ' . PHP_EOL;
}
echo 'THE END';*/