update to PHP-8.1
[m6w6/seekat] / lib / Exception / functions.php
1 <?php
2
3 namespace seekat\Exception;
4
5 use Throwable;
6
7 /**
8 * @param string|Throwable $message
9 * @return Throwable
10 */
11 function exception(&$message) : Throwable {
12 if ($message instanceof Throwable){
13 $exception = $message;
14 $message = $exception->getMessage();
15 } else {
16 $exception = new \Exception($message);
17 }
18 return $exception;
19 }
20
21 /**
22 * Canonical error message from a string or Exception
23 * @param string|Throwable $error
24 */
25 function message(&$error) : ?string {
26 if ($error instanceof Throwable) {
27 $message = $error->getMessage();
28 } else {
29 $message = $error;
30 $error = new \Exception($message);
31 }
32 return $message;
33 }