flush
[m6w6/seekat] / lib / Exception / functions.php
index 08c8ddbca656d3cfc88d8f9065b9f6b6223a9fd6..9045cb3df3473f1f41df7a9422fb5f4a8c37b432 100644 (file)
@@ -2,6 +2,20 @@
 
 namespace seekat\Exception;
 
+/**
+ * @param $message
+ * @return \Throwable
+ */
+function exception(&$message) : \Throwable {
+       if ($message instanceof \Throwable){
+               $exception = $message;
+               $message = $exception->getMessage();
+       } else {
+               $exception = new \Exception($message);
+       }
+       return $exception;
+}
+
 /**
  * Canonical error message from a string or Exception
  * @param string|Exception $error
@@ -12,7 +26,7 @@ function message(&$error) : string {
                $message = $error->getMessage();
        } else {
                $message = $error;
-               $error = new \Exception($error);
+               $error = new \Exception($message);
        }
        return $message;
 }