Error handling

Swoft provides a complete exception and error handling mechanism. Unlike the usual fpm case, swowt divides the error into different scene types.


 composer require swoft/error 

Error scenario

The division of scene types: mainly based on the scope of the swoole callback event.

In different scenarios, even if an exception or error is thrown in the same place, the processing may be different.

For example: db throws a DbException , in the http run scene you need to process a Return object. In environments such as cli, you can only process without returning any results.

Error scenario type

The scene type defined by swowt is defined in Swoft\Error\ErrorType .

 <?php declare(strict_types=1);

namespace Swoft\Error;

 * Class ErrorType
 * @since 2.0
final class ErrorType
    public const CLI  = 2;
    public const RPC  = 3;
    public const UDP  = 4;
    public const TCP  = 5;
    public const SOCK = 7;
    public const TASK = 8;

    // HTTP server
    public const HTTP = 16;

    // WebSocket server
    public const WS_HS  = 21;
    public const WS_OPN = 22;
    public const WS_MSG = 23;
    public const WS_CLS = 24;

    public const SYS = 85;

    // default
    public const DEF     = 90;
    public const DEFAULT = 90;

For specific usage of exception handling, please continue to the next document.

Git warehouse

Participate in the contribution

Welcome to participate in the contribution, you can

  • Fork our development warehouse swewt/component
  • Modify the code and then initiate the PR
  • About PR launch of Notes