Jelajahi Sumber

Remove unnecessary exception comments

walkor 1 tahun lalu
induk
melakukan
dc35e03f9f

+ 1 - 6
src/Connection/AsyncTcpConnection.php

@@ -154,7 +154,6 @@ class AsyncTcpConnection extends TcpConnection
      *
      * @param string $remoteAddress
      * @param array $socketContext
-     * @throws Exception
      */
     public function __construct(string $remoteAddress, array $socketContext = [])
     {
@@ -195,7 +194,7 @@ class AsyncTcpConnection extends TcpConnection
             if (!class_exists($this->protocol)) {
                 $this->protocol = "\\Workerman\\Protocols\\$scheme";
                 if (!class_exists($this->protocol)) {
-                    throw new Exception("class \\Protocols\\$scheme not exist");
+                    throw new RuntimeException("class \\Protocols\\$scheme not exist");
                 }
             }
         } else {
@@ -216,7 +215,6 @@ class AsyncTcpConnection extends TcpConnection
      *
      * @param int $after
      * @return void
-     * @throws Throwable
      */
     public function reconnect(int $after = 0): void
     {
@@ -236,7 +234,6 @@ class AsyncTcpConnection extends TcpConnection
      * Do connect.
      *
      * @return void
-     * @throws Throwable
      */
     public function connect(): void
     {
@@ -302,7 +299,6 @@ class AsyncTcpConnection extends TcpConnection
      * @param int $code
      * @param mixed $msg
      * @return void
-     * @throws Throwable
      */
     protected function emitError(int $code, mixed $msg): void
     {
@@ -351,7 +347,6 @@ class AsyncTcpConnection extends TcpConnection
      * Check connection is successfully established or failed.
      *
      * @return void
-     * @throws Throwable
      */
     public function checkConnection(): void
     {

+ 3 - 6
src/Connection/AsyncUdpConnection.php

@@ -17,6 +17,7 @@ declare(strict_types=1);
 namespace Workerman\Connection;
 
 use Exception;
+use RuntimeException;
 use Throwable;
 use Workerman\Protocols\ProtocolInterface;
 use Workerman\Worker;
@@ -70,7 +71,7 @@ class AsyncUdpConnection extends UdpConnection
      * Construct.
      *
      * @param string $remoteAddress
-     * @throws Exception
+     * @throws Throwable
      */
     public function __construct($remoteAddress, $contextOption = [])
     {
@@ -83,7 +84,7 @@ class AsyncUdpConnection extends UdpConnection
             if (!class_exists($this->protocol)) {
                 $this->protocol = "\\Workerman\\Protocols\\$scheme";
                 if (!class_exists($this->protocol)) {
-                    throw new Exception("class \\Protocols\\$scheme not exist");
+                    throw new RuntimeException("class \\Protocols\\$scheme not exist");
                 }
             }
         }
@@ -97,7 +98,6 @@ class AsyncUdpConnection extends UdpConnection
      *
      * @param resource $socket
      * @return void
-     * @throws Throwable
      */
     public function baseRead($socket): void
     {
@@ -127,7 +127,6 @@ class AsyncUdpConnection extends UdpConnection
      * @param mixed $data
      * @param bool $raw
      * @return void
-     * @throws Throwable
      */
     public function close(mixed $data = null, bool $raw = false): void
     {
@@ -154,7 +153,6 @@ class AsyncUdpConnection extends UdpConnection
      * @param mixed $sendBuffer
      * @param bool $raw
      * @return bool|null
-     * @throws Throwable
      */
     public function send(mixed $sendBuffer, bool $raw = false): bool|null
     {
@@ -176,7 +174,6 @@ class AsyncUdpConnection extends UdpConnection
      * Connect.
      *
      * @return void
-     * @throws Throwable
      */
     public function connect(): void
     {

+ 2 - 6
src/Connection/ConnectionInterface.php

@@ -170,7 +170,6 @@ abstract class ConnectionInterface
     /**
      * @param Throwable $exception
      * @return void
-     * @throws Throwable
      */
     public function error(Throwable $exception): void
     {
@@ -181,11 +180,8 @@ abstract class ConnectionInterface
         try {
             ($this->errorHandler)($exception);
         } catch (Throwable $exception) {
-            if ($this->eventLoop instanceof Event) {
-                echo $exception;
-                return;
-            }
-            throw $exception;
+            Worker::stopAll(250, $exception);
+            return;
         }
     }
 }

+ 1 - 11
src/Connection/TcpConnection.php

@@ -400,7 +400,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      * @param mixed $sendBuffer
      * @param bool $raw
      * @return bool|null
-     * @throws Throwable
      */
     public function send(mixed $sendBuffer, bool $raw = false): bool|null
     {
@@ -414,7 +413,7 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
             $parser = $this->protocol;
             try {
                 $sendBuffer = $parser::encode($sendBuffer, $this);
-            } catch(\Throwable $e) {
+            } catch(Throwable $e) {
                 $this->error($e);
             }
             if ($sendBuffer === '') {
@@ -605,7 +604,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      * Resumes reading after a call to pauseRecv.
      *
      * @return void
-     * @throws Throwable
      */
     public function resumeRecv(): void
     {
@@ -623,7 +621,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      * @param resource $socket
      * @param bool $checkEof
      * @return void
-     * @throws Throwable
      */
     public function baseRead($socket, bool $checkEof = true): void
     {
@@ -764,7 +761,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      * Base write handler.
      *
      * @return void
-     * @throws Throwable
      */
     public function baseWrite(): void
     {
@@ -811,7 +807,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      *
      * @param resource $socket
      * @return bool|int
-     * @throws Throwable
      */
     public function doSslHandshake($socket): bool|int
     {
@@ -898,7 +893,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      * @param mixed $data
      * @param bool $raw
      * @return void
-     * @throws Throwable
      */
     public function close(mixed $data = null, bool $raw = false): void
     {
@@ -964,7 +958,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      * Check whether send buffer will be full.
      *
      * @return void
-     * @throws Throwable
      */
     protected function checkBufferWillFull(): void
     {
@@ -981,7 +974,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      * Whether send buffer is full.
      *
      * @return bool
-     * @throws Throwable
      */
     protected function bufferIsFull(): bool
     {
@@ -1013,7 +1005,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      * Destroy connection.
      *
      * @return void
-     * @throws Throwable
      */
     public function destroy(): void
     {
@@ -1101,7 +1092,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      * Destruct.
      *
      * @return void
-     * @throws Throwable
      */
     public function __destruct()
     {

+ 10 - 9
src/Events/Select.php

@@ -16,6 +16,8 @@ declare(strict_types=1);
 
 namespace Workerman\Events;
 
+use SplPriorityQueue;
+use Throwable;
 use function count;
 use function max;
 use function microtime;
@@ -86,9 +88,9 @@ final class Select implements EventInterface
      * Timer scheduler.
      * {['data':timer_id, 'priority':run_timestamp], ..}
      *
-     * @var \SplPriorityQueue
+     * @var SplPriorityQueue
      */
-    private \SplPriorityQueue $scheduler;
+    private SplPriorityQueue $scheduler;
 
     /**
      * All timer event listeners.
@@ -122,8 +124,8 @@ final class Select implements EventInterface
      */
     public function __construct()
     {
-        $this->scheduler = new \SplPriorityQueue();
-        $this->scheduler->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
+        $this->scheduler = new SplPriorityQueue();
+        $this->scheduler->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
     }
 
     /**
@@ -299,7 +301,6 @@ final class Select implements EventInterface
      * Tick for timer.
      *
      * @return void
-     * @throws \Throwable
      */
     protected function tick(): void
     {
@@ -349,8 +350,8 @@ final class Select implements EventInterface
      */
     public function deleteAllTimer(): void
     {
-        $this->scheduler = new \SplPriorityQueue();
-        $this->scheduler->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
+        $this->scheduler = new SplPriorityQueue();
+        $this->scheduler->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
         $this->eventTimer = [];
     }
 
@@ -367,7 +368,7 @@ final class Select implements EventInterface
                 // Waiting read/write/signal/timeout events.
                 try {
                     @stream_select($read, $write, $except, 0, $this->selectTimeout);
-                } catch (\Throwable) {
+                } catch (Throwable) {
                     // do nothing
                 }
             } else {
@@ -450,7 +451,7 @@ final class Select implements EventInterface
     {
         try {
             $func(...$args);
-        } catch (\Throwable $e) {
+        } catch (Throwable $e) {
             if ($this->errorHandler === null) {
                 echo $e;
             } else {

+ 1 - 4
src/Protocols/Http.php

@@ -86,7 +86,7 @@ class Http
      *
      * @param bool $value
      */
-    public static function enableCache(bool $value)
+    public static function enableCache(bool $value): void
     {
         static::$enableCache = $value;
     }
@@ -97,7 +97,6 @@ class Http
      * @param string $buffer
      * @param TcpConnection $connection
      * @return int
-     * @throws Throwable
      */
     public static function input(string $buffer, TcpConnection $connection): int
     {
@@ -194,7 +193,6 @@ class Http
      * @param string|Response $response
      * @param TcpConnection $connection
      * @return string
-     * @throws Throwable
      */
     public static function encode(mixed $response, TcpConnection $connection): string
     {
@@ -266,7 +264,6 @@ class Http
      * @param resource $handler
      * @param int $offset
      * @param int $length
-     * @throws Throwable
      */
     protected static function sendStream(TcpConnection $connection, $handler, int $offset = 0, int $length = 0): void
     {

+ 2 - 2
src/Protocols/Http/Request.php

@@ -226,7 +226,7 @@ class Request implements Stringable
             $mapped = array();
 
             foreach ($cookies as $cookie) {
-                $cookie = explode('=', $cookie);
+                $cookie = explode('=', $cookie, 2);
                 if (count($cookie) !== 2) {
                     continue;
                 }
@@ -678,7 +678,7 @@ class Request implements Stringable
                     break;
 
                 case "webkitrelativepath":
-                    $file['full_path'] = \trim($value);
+                    $file['full_path'] = trim($value);
                     break;
             }
         }

+ 3 - 2
src/Protocols/Http/Session.php

@@ -17,6 +17,7 @@ declare(strict_types=1);
 namespace Workerman\Protocols\Http;
 
 use Exception;
+use Random\RandomException;
 use RuntimeException;
 use Workerman\Protocols\Http\Session\FileSessionHandler;
 use Workerman\Protocols\Http\Session\SessionHandlerInterface;
@@ -153,7 +154,7 @@ class Session
      *
      * @var bool
      */
-    protected $isSafe = true;
+    protected bool $isSafe = true;
 
     /**
      * Session constructor.
@@ -437,7 +438,7 @@ class Session
      * __destruct.
      *
      * @return void
-     * @throws Exception
+     * @throws RandomException
      */
     public function __destruct()
     {

+ 18 - 17
src/Protocols/Websocket.php

@@ -16,7 +16,6 @@ declare(strict_types=1);
 
 namespace Workerman\Protocols;
 
-use Exception;
 use Throwable;
 use Workerman\Connection\ConnectionInterface;
 use Workerman\Connection\TcpConnection;
@@ -24,8 +23,11 @@ use Workerman\Protocols\Http\Request;
 use Workerman\Worker;
 use function base64_encode;
 use function chr;
+use function deflate_add;
+use function deflate_init;
 use function floor;
-use function gettype;
+use function inflate_add;
+use function inflate_init;
 use function is_scalar;
 use function ord;
 use function pack;
@@ -37,6 +39,8 @@ use function strlen;
 use function strpos;
 use function substr;
 use function unpack;
+use const ZLIB_DEFAULT_STRATEGY;
+use const ZLIB_ENCODING_RAW;
 
 /**
  * WebSocket protocol.
@@ -77,7 +81,6 @@ class Websocket
      * @param string $buffer
      * @param TcpConnection $connection
      * @return int
-     * @throws Throwable
      */
     public static function input(string $buffer, TcpConnection $connection): int
     {
@@ -256,19 +259,18 @@ class Websocket
      * @param mixed $buffer
      * @param TcpConnection $connection
      * @return string
-     * @throws Throwable
      */
     public static function encode(mixed $buffer, TcpConnection $connection): string
     {
         if (!is_scalar($buffer)) {
-            throw new Exception("You can't send(" . gettype($buffer) . ") to client, you need to convert it to string. ");
+            $buffer = json_encode($buffer, JSON_UNESCAPED_UNICODE);
         }
 
         if (empty($connection->websocketType)) {
             $connection->websocketType = static::BINARY_TYPE_BLOB;
         }
 
-        if (\ord($connection->websocketType) & 64) {
+        if (ord($connection->websocketType) & 64) {
             $buffer = static::deflate($connection, $buffer);
         }
 
@@ -372,23 +374,23 @@ class Websocket
      * @param bool $isFinFrame
      * @return false|string
      */
-    protected static function inflate(TcpConnection $connection, string $buffer, bool $isFinFrame)
+    protected static function inflate(TcpConnection $connection, string $buffer, bool $isFinFrame): bool|string
     {
         if (!isset($connection->context->inflator)) {
-            $connection->context->inflator = \inflate_init(
-                \ZLIB_ENCODING_RAW,
+            $connection->context->inflator = inflate_init(
+                ZLIB_ENCODING_RAW,
                 [
                     'level'    => -1,
                     'memory'   => 8,
                     'window'   => 15,
-                    'strategy' => \ZLIB_DEFAULT_STRATEGY
+                    'strategy' => ZLIB_DEFAULT_STRATEGY
                 ]
             );
         }
         if ($isFinFrame) {
             $buffer .= "\x00\x00\xff\xff";
         }
-        return \inflate_add($connection->context->inflator, $buffer);
+        return inflate_add($connection->context->inflator, $buffer);
     }
 
     /**
@@ -398,20 +400,20 @@ class Websocket
      * @param string $buffer
      * @return false|string
      */
-    protected static function deflate(TcpConnection $connection, string $buffer)
+    protected static function deflate(TcpConnection $connection, string $buffer): bool|string
     {
         if (!isset($connection->context->deflator)) {
-            $connection->context->deflator = \deflate_init(
-                \ZLIB_ENCODING_RAW,
+            $connection->context->deflator = deflate_init(
+                ZLIB_ENCODING_RAW,
                 [
                     'level'    => -1,
                     'memory'   => 8,
                     'window'   => 15,
-                    'strategy' => \ZLIB_DEFAULT_STRATEGY
+                    'strategy' => ZLIB_DEFAULT_STRATEGY
                 ]
             );
         }
-        return \substr(\deflate_add($connection->context->deflator, $buffer), 0, -4);
+        return substr(deflate_add($connection->context->deflator, $buffer), 0, -4);
     }
 
     /**
@@ -420,7 +422,6 @@ class Websocket
      * @param string $buffer
      * @param TcpConnection $connection
      * @return int
-     * @throws Throwable
      */
     public static function dealHandshake(string $buffer, TcpConnection $connection): int
     {

+ 6 - 11
src/Protocols/Ws.php

@@ -16,7 +16,6 @@ declare(strict_types=1);
 
 namespace Workerman\Protocols;
 
-use Exception;
 use Throwable;
 use Workerman\Connection\AsyncTcpConnection;
 use Workerman\Connection\ConnectionInterface;
@@ -25,10 +24,8 @@ use Workerman\Timer;
 use Workerman\Worker;
 use function base64_encode;
 use function bin2hex;
+use function explode;
 use function floor;
-use function gettype;
-use function is_array;
-use function is_scalar;
 use function ord;
 use function pack;
 use function preg_match;
@@ -65,7 +62,6 @@ class Ws
      * @param string $buffer
      * @param AsyncTcpConnection $connection
      * @return int|false
-     * @throws Throwable
      */
     public static function input(string $buffer, AsyncTcpConnection $connection): bool|int
     {
@@ -393,7 +389,6 @@ class Ws
      * @param string $buffer
      * @param AsyncTcpConnection $connection
      * @return bool|int
-     * @throws Throwable
      */
     public static function dealHandshake(string $buffer, AsyncTcpConnection $connection): bool|int
     {
@@ -455,9 +450,9 @@ class Ws
      */
     protected static function parseResponse(string $buffer): Response
     {
-        [$http_header, ] = \explode("\r\n\r\n", $buffer, 2);
-        $header_data = \explode("\r\n", $http_header);
-        [$protocol, $status, $phrase] = \explode(' ', $header_data[0], 3);
+        [$http_header, ] = explode("\r\n\r\n", $buffer, 2);
+        $header_data = explode("\r\n", $http_header);
+        [$protocol, $status, $phrase] = explode(' ', $header_data[0], 3);
         $protocolVersion = substr($protocol, 5);
         unset($header_data[0]);
         $headers = [];
@@ -466,8 +461,8 @@ class Ws
             if (empty($content)) {
                 continue;
             }
-            list($key, $value) = \explode(':', $content, 2);
-            $value = \trim($value);
+            list($key, $value) = explode(':', $content, 2);
+            $value = trim($value);
             $headers[$key] = $value;
         }
         return (new Response())->withStatus((int)$status, $phrase)->withHeaders($headers)->withProtocolVersion($protocolVersion);

+ 21 - 45
src/Worker.php

@@ -21,6 +21,7 @@ use Exception;
 use Revolt\EventLoop;
 use RuntimeException;
 use stdClass;
+use Stringable;
 use Throwable;
 use Workerman\Connection\ConnectionInterface;
 use Workerman\Connection\TcpConnection;
@@ -30,6 +31,9 @@ use Workerman\Events\EventInterface;
 use Workerman\Events\Revolt;
 use Workerman\Events\Select;
 use Workerman\Protocols\ProtocolInterface;
+use function defined;
+use function function_exists;
+use function is_resource;
 use function method_exists;
 use function restore_error_handler;
 use function set_error_handler;
@@ -38,6 +42,10 @@ use function stream_socket_recvfrom;
 use function substr;
 use function array_walk;
 use function get_class;
+use const DIRECTORY_SEPARATOR;
+use const PHP_SAPI;
+use const PHP_VERSION;
+use const STDOUT;
 
 /**
  * Worker class
@@ -369,14 +377,6 @@ class Worker
     protected string $socketName = '';
 
     /**
-     * parse from socketName avoid parse again in master or worker
-     * LocalSocket The format is like tcp://0.0.0.0:8080
-     *
-     * @var ?string
-     */
-    protected ?string $localSocket = null;
-
-    /**
      * Context of socket.
      *
      * @var resource
@@ -566,7 +566,6 @@ class Worker
      * Run all worker instances.
      *
      * @return void
-     * @throws Throwable
      */
     public static function runAll(): void
     {
@@ -585,7 +584,7 @@ class Worker
             static::forkWorkers();
             static::resetStd();
             static::monitorWorkers();
-        } catch (\Throwable $e) {
+        } catch (Throwable $e) {
             static::log($e);
         }
     }
@@ -598,19 +597,19 @@ class Worker
     protected static function checkSapiEnv(): void
     {
         // Only for cli and micro.
-        if (!in_array(\PHP_SAPI, ['cli', 'micro'])) {
+        if (!in_array(PHP_SAPI, ['cli', 'micro'])) {
             exit("Only run in command line mode\n");
         }
     }
 
     private static function initStdOut(): void
     {
-        $defaultStream = fn () => \defined('STDOUT') ? \STDOUT : (@fopen('php://stdout', 'w') ?: fopen('php://output', 'w'));
+        $defaultStream = fn () => defined('STDOUT') ? STDOUT : (@fopen('php://stdout', 'w') ?: fopen('php://output', 'w'));
         static::$outputStream ??= $defaultStream(); //@phpstan-ignore-line
-        if (!\is_resource(self::$outputStream) || get_resource_type(self::$outputStream) !== 'stream') {
+        if (!is_resource(self::$outputStream) || get_resource_type(self::$outputStream) !== 'stream') {
             $type = get_debug_type(self::$outputStream);
             static::$outputStream = $defaultStream();
-            throw new \RuntimeException(sprintf('The $outputStream must to be a stream, %s given', $type));
+            throw new RuntimeException(sprintf('The $outputStream must to be a stream, %s given', $type));
         }
 
         static::$outputDecorated ??= self::hasColorSupport();
@@ -631,8 +630,8 @@ class Worker
             return true;
         }
 
-        if (\DIRECTORY_SEPARATOR === '\\') {
-            return (\function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(self::$outputStream))
+        if (DIRECTORY_SEPARATOR === '\\') {
+            return (function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(self::$outputStream))
                 || getenv('ANSICON') !== false
                 || getenv('ConEmuANSI') === 'ON'
                 || getenv('TERM') === 'xterm';
@@ -755,7 +754,6 @@ class Worker
      * Init All worker instances.
      *
      * @return void
-     * @throws Exception
      */
     protected static function initWorkers(): void
     {
@@ -871,7 +869,7 @@ class Worker
         $jitStatus = function_exists('opcache_get_status') && (opcache_get_status()['jit']['on'] ?? false) === true ? 'on' : 'off';
         if (DIRECTORY_SEPARATOR !== '/') {
             static::safeEcho("---------------------------------------------- WORKERMAN -----------------------------------------------\r\n");
-            static::safeEcho('Workerman version:'. static::VERSION. '          PHP version:'. \PHP_VERSION . " (Jit $jitStatus)\r\n");
+            static::safeEcho('Workerman version:'. static::VERSION. '          PHP version:'. PHP_VERSION . " (Jit $jitStatus)\r\n");
             static::safeEcho("----------------------------------------------- WORKERS ------------------------------------------------\r\n");
             static::safeEcho("worker                                          listen                              processes   status\r\n");
             return;
@@ -1244,7 +1242,6 @@ class Worker
      * Reinstall signal handler.
      *
      * @return void
-     * @throws Throwable
      */
     protected static function reinstallSignal(): void
     {
@@ -1262,7 +1259,6 @@ class Worker
      * Signal handler.
      *
      * @param int $signal
-     * @throws Throwable
      */
     protected static function signalHandler(int $signal): void
     {
@@ -1303,8 +1299,6 @@ class Worker
 
     /**
      * Run as daemon mode.
-     *
-     * @throws Exception
      */
     protected static function daemonize(): void
     {
@@ -1373,8 +1367,6 @@ class Worker
 
     /**
      * Save pid.
-     *
-     * @throws Exception
      */
     protected static function saveMasterPid(): void
     {
@@ -1418,7 +1410,6 @@ class Worker
      * Fork some worker processes.
      *
      * @return void
-     * @throws Throwable
      */
     protected static function forkWorkers(): void
     {
@@ -1433,7 +1424,6 @@ class Worker
      * Fork some worker processes.
      *
      * @return void
-     * @throws Throwable
      */
     protected static function forkWorkersForLinux(): void
     {
@@ -1458,7 +1448,6 @@ class Worker
      * Fork some worker processes.
      *
      * @return void
-     * @throws Throwable
      */
     protected static function forkWorkersForWindows(): void
     {
@@ -1509,7 +1498,7 @@ class Worker
             $worker->run();
             static::$globalEvent->run();
             if (static::$status !== self::STATUS_SHUTDOWN) {
-                $err = new Exception('event-loop exited');
+                $err = new RuntimeException('event-loop exited');
                 static::log($err);
                 exit(250);
             }
@@ -1589,7 +1578,6 @@ class Worker
      * Fork one worker process.
      *
      * @param self $worker
-     * @throws Exception|Throwable
      */
     protected static function forkOneWorkerForLinux(self $worker): void
     {
@@ -1736,7 +1724,6 @@ class Worker
      * Monitor all child processes.
      *
      * @return void
-     * @throws Throwable
      */
     protected static function monitorWorkersForLinux(): void
     {
@@ -1810,7 +1797,6 @@ class Worker
      * Monitor all child processes.
      *
      * @return void
-     * @throws Throwable
      */
     protected static function monitorWorkersForWindows(): void
     {
@@ -1844,7 +1830,6 @@ class Worker
      * Execute reload.
      *
      * @return void
-     * @throws Throwable
      */
     protected static function reload(): void
     {
@@ -1923,7 +1908,6 @@ class Worker
      *
      * @param int $code
      * @param mixed $log
-     * @throws Throwable
      */
     public static function stopAll(int $code = 0, mixed $log = ''): void
     {
@@ -1966,7 +1950,7 @@ class Worker
                     // Ignore Swoole ExitException: Swoole exit.
                     exit($code);
                     /** @phpstan-ignore-next-line */
-                } catch (\Exception) {
+                } catch (Throwable) {
                     // do nothing
                 }
             }
@@ -2202,11 +2186,11 @@ class Worker
     /**
      * Log.
      *
-     * @param \Stringable|string $msg
+     * @param Stringable|string $msg
      * @param bool $decorated
      * @return void
      */
-    public static function log(\Stringable|string $msg, bool $decorated = false): void
+    public static function log(Stringable|string $msg, bool $decorated = false): void
     {
         $msg = trim((string)$msg);
 
@@ -2298,8 +2282,6 @@ class Worker
 
     /**
      * Listen.
-     *
-     * @throws Exception
      */
     public function listen(): void
     {
@@ -2323,7 +2305,7 @@ class Worker
             // Create an Internet or Unix domain server socket.
             $this->mainSocket = stream_socket_server($localSocket, $errno, $errmsg, $flags, $this->socketContext);
             if (!$this->mainSocket) {
-                throw new Exception($errmsg);
+                throw new RuntimeException($errmsg);
             }
 
             if ($this->transport === 'ssl') {
@@ -2372,8 +2354,6 @@ class Worker
 
     /**
      * Parse local socket address.
-     *
-     * @throws Exception
      */
     protected function parseSocketAddress(): ?string
     {
@@ -2448,7 +2428,6 @@ class Worker
      * Run worker instance.
      *
      * @return void
-     * @throws Throwable
      */
     public function run(): void
     {
@@ -2470,7 +2449,6 @@ class Worker
      * Stop current worker instance.
      *
      * @return void
-     * @throws Throwable
      */
     public function stop(): void
     {
@@ -2509,7 +2487,6 @@ class Worker
      *
      * @param resource $socket
      * @return void
-     * @throws Throwable
      */
     protected function acceptTcpConnection(mixed $socket): void
     {
@@ -2550,7 +2527,6 @@ class Worker
      *
      * @param resource $socket
      * @return void
-     * @throws Throwable
      */
     protected function acceptUdpConnection(mixed $socket): void
     {