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